rust clap: how can I have a cli args of: 1. command1 2. [string] command2 use derive
- User
rust clap: how can I have a cli args of:
- command1
- [string] command2 use derive
Assistant
Here's how you can set up CLI args with two commands using clap's derive API:
use clap::{Parser, Subcommand}; #[derive(Parser)] #[command(name = "myapp")] #[command(about = "A CLI with two commands")] struct Cli { #[command(subcommand)] command: Commands, } #[derive(Subcommand)] enum Commands { Command1, Command2 { /// The string argument for command2 value: String, }, } fn main() { let cli = Cli::parse(); match &cli.command { Commands::Command1 => { println!("Executing command1"); } Commands::Command2 { value } => { println!("Executing command2 with value: {}", value); } } }
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.