Agent Skills: Rust CLI Skill

Build professional CLI applications with clap and TUI

rustcliclaptuicommand-line
developmentID: pluginagentmarketplace/custom-plugin-rust/rust-cli

Skill Files

Browse the full folder contents for rust-cli.

Download Skill

Loading file tree…

skills/rust-cli/SKILL.md

Skill Metadata

Name
rust-cli
Description
Build professional CLI applications with clap and TUI

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

| Problem | Solution | |---------|----------| | Args not parsed | Add features = ["derive"] | | Colors not showing | Check terminal support |

Resources