Skip to content

v0.4.0

Compare
Choose a tag to compare
@nihaals nihaals released this 04 Oct 23:18
· 13 commits to main since this release
v0.4.0
17e547d

Additions

  • Implement ValueEnum
  • Implement Debug

Breaking changes

  • Update Clap to v4
  • Remove implementation of ArgEnum
  • Remove methods for pre-ValueEnum builder API
    • Remove FromStr implementation
    • Remove Shell::possible_values()

Migration guide

See the examples diff, including changes needed to update from Clap v3 to v4:

Builder

--- a/examples/builder.rs
+++ b/examples/builder.rs
 use clap::{Arg, Command};

-fn build_cli() -> Command<'static> {
+fn build_cli() -> Command {
     Command::new(env!("CARGO_PKG_NAME"))
         .subcommand_required(true)
         .subcommand(
             Command::new("completions")
                 .about("Generate shell completions")
                 .arg(
                     Arg::new("shell")
                         .value_name("SHELL")
                         .help("The shell to generate the completions for")
                         .required(true)
-                        .possible_values(clap_complete_command::Shell::possible_values()),
+                        .value_parser(
+                            clap::builder::EnumValueParser::<clap_complete_command::Shell>::new(),
+                        ),
                 ),
         )
 }

 fn main() {
     let matches = build_cli().get_matches();

     match matches.subcommand() {
         Some(("completions", sub_matches)) => {
-            if let Ok(shell) = sub_matches.value_of_t::<clap_complete_command::Shell>("shell") {
+            if let Some(shell) = sub_matches.get_one::<clap_complete_command::Shell>("shell") {
                 let mut command = build_cli();
                 shell.generate(&mut command, &mut std::io::stdout());
             }
         }
         _ => {
             unreachable!("Exhausted list of subcommands and `subcommand_required` prevents `None`")
         }
     }
 }

Derive

--- a/examples/derive.rs
+++ b/examples/derive.rs
-use clap::{IntoApp, Parser, Subcommand};
+use clap::{CommandFactory, Parser, Subcommand};

 #[derive(Parser)]
 struct Cli {
-    #[clap(subcommand)]
+    #[command(subcommand)]
     command: Commands,
 }

 #[derive(Subcommand)]
 enum Commands {
     /// Generate shell completions
     Completions {
         /// The shell to generate the completions for
-        #[clap(arg_enum)]
+        #[arg(value_enum)]
         shell: clap_complete_command::Shell,
     },
 }

 fn main() {
     let cli = Cli::parse();

     match cli.command {
         Commands::Completions { shell } => {
             shell.generate(&mut Cli::command(), &mut std::io::stdout());
         }
     }
 }

Full Changelog: v0.3.4...v0.4.0