rust-cli

Build professional CLI applications with clap and TUI

Safety Notice

This listing is imported from skills.sh public index metadata. Review upstream SKILL.md and repository scripts before running.

Copy this and send it to your AI assistant to learn

Install skill "rust-cli" with this command: npx skills add pluginagentmarketplace/custom-plugin-rust/pluginagentmarketplace-custom-plugin-rust-rust-cli

Rust CLI Skill

Build professional command-line applications with clap, colored output, and interactive features.

Quick Start

Basic CLI with Clap

[dependencies]
clap = { version = "4", features = ["derive"] }
anyhow = "1"
use clap::{Parser, Subcommand};

#[derive(Parser)]
#[command(name = "myapp", version, about)]
struct Cli {
    #[arg(short, long)]
    verbose: bool,

    #[command(subcommand)]
    command: Commands,
}

#[derive(Subcommand)]
enum Commands {
    Init { name: String },
    Build { #[arg(short, long)] release: bool },
}

fn main() -> anyhow::Result<()> {
    let cli = Cli::parse();

    match cli.command {
        Commands::Init { name } => println!("Creating: {}", name),
        Commands::Build { release } => println!("Building..."),
    }
    Ok(())
}

Colored Output

use colored::Colorize;

println!("{}", "Success!".green().bold());
println!("{}", "Error!".red());

Progress Bars

use indicatif::{ProgressBar, ProgressStyle};

let pb = ProgressBar::new(100);
pb.set_style(ProgressStyle::default_bar()
    .template("{bar:40} {pos}/{len}")?);

for _ in 0..100 {
    pb.inc(1);
}
pb.finish();

Interactive Prompts

use dialoguer::{Confirm, Input, Select};

let name: String = Input::new()
    .with_prompt("Project name")
    .interact_text()?;

if Confirm::new().with_prompt("Continue?").interact()? {
    // proceed
}

Common Patterns

Error Handling

fn main() {
    if let Err(e) = run() {
        eprintln!("{}: {}", "error".red(), e);
        std::process::exit(1);
    }
}

Testing CLI

use assert_cmd::Command;
use predicates::prelude::*;

#[test]
fn test_help() {
    Command::cargo_bin("myapp").unwrap()
        .arg("--help")
        .assert()
        .success();
}

Troubleshooting

ProblemSolution
Args not parsedAdd features = ["derive"]
Colors not showingCheck terminal support

Resources

Source Transparency

This detail page is rendered from real SKILL.md content. Trust labels are metadata-based hints, not a safety guarantee.

Related Skills

Related by shared tags or category signals.

Coding

async-programming

No summary provided by upstream source.

Repository SourceNeeds Review
Automation

error-handling

No summary provided by upstream source.

Repository SourceNeeds Review
Automation

rust-wasm

No summary provided by upstream source.

Repository SourceNeeds Review