diff options
Diffstat (limited to 'src/args.rs')
-rw-r--r-- | src/args.rs | 56 |
1 files changed, 31 insertions, 25 deletions
diff --git a/src/args.rs b/src/args.rs index 9318202..b4e6f84 100644 --- a/src/args.rs +++ b/src/args.rs @@ -3,15 +3,15 @@ use std::ffi::OsString; use std::iter; use std::path::PathBuf; -use structopt::StructOpt; +use clap::Parser; -#[derive(StructOpt, Debug, PartialEq, Eq, Clone)] -#[structopt(author, about)] +#[derive(clap::Parser, Debug, PartialEq, Eq, Clone)] +#[clap(author, about)] #[allow(clippy::struct_excessive_bools)] pub struct Args { /// Cause environment variables, including those with null values, to override macro /// assignments within makefiles. - #[structopt(short, long)] + #[clap(short, long)] pub environment_overrides: bool, /// Specify a different makefile (or '-' for standard input). @@ -21,12 +21,12 @@ pub struct Args { /// be multiple instances of this option, and they shall be processed in the order /// specified. The effect of specifying the same option-argument more than once is /// unspecified. - #[structopt( - short = "f", + #[clap( + short = 'f', long = "file", visible_alias = "makefile", number_of_values = 1, - parse(from_os_str) + value_parser )] pub makefile: Vec<PathBuf>, @@ -34,17 +34,17 @@ pub struct Args { /// /// This mode is the same as if the special target .IGNORE were specified without /// prerequisites. - #[structopt(short, long)] + #[clap(short, long)] pub ignore_errors: bool, /// Continue to update other targets that do not depend on the current target if a /// non-ignored error occurs while executing the commands to bring a target /// up-to-date. - #[structopt( + #[clap( short, long, - overrides_with = "keep-going", - overrides_with = "no-keep-going" + overrides_with = "keep_going", + overrides_with = "no_keep_going" )] pub keep_going: bool, @@ -54,8 +54,8 @@ pub struct Args { /// However, lines with a <plus-sign> ( '+' ) prefix shall be executed. In this mode, /// lines with an at-sign ( '@' ) character prefix shall be written to standard /// output. - #[structopt( - short = "n", + #[clap( + short = 'n', long, visible_alias = "just-print", visible_alias = "recon" @@ -66,7 +66,7 @@ pub struct Args { /// descriptions. /// /// The output format is unspecified. - #[structopt(short, long, visible_alias = "print-data-base")] + #[clap(short, long, visible_alias = "print-data-base")] pub print_everything: bool, /// Return a zero exit value if the target file is up-to-date; otherwise, return an @@ -75,11 +75,11 @@ pub struct Args { /// Targets shall not be updated if this option is specified. However, a makefile /// command line (associated with the targets) with a <plus-sign> ( '+' ) prefix /// shall be executed. - #[structopt(short, long)] + #[clap(short, long)] pub question: bool, /// Clear the suffix list and do not use the built-in rules. - #[structopt(short = "r", long)] + #[clap(short = 'r', long)] pub no_builtin_rules: bool, /// Terminate make if an error occurs while executing the commands to bring a target @@ -87,13 +87,13 @@ pub struct Args { /// reason). /// /// This shall be the default and the opposite of -k. - #[structopt( - short = "S", + #[clap( + short = 'S', long, visible_alias = "stop", - hidden = true, - overrides_with = "keep-going", - overrides_with = "no-keep-going" + hide = true, + overrides_with = "keep_going", + overrides_with = "no_keep_going" )] pub no_keep_going: bool, @@ -102,7 +102,7 @@ pub struct Args { /// /// This mode shall be the same as if the special target .SILENT were specified /// without prerequisites. - #[structopt(short, long, visible_alias = "quiet")] + #[clap(short, long, visible_alias = "quiet")] pub silent: bool, /// Update the modification time of each target as though a touch target had been @@ -113,12 +113,12 @@ pub struct Args { /// target file indicating the name of the file and that it was touched. Normally, /// the makefile command lines associated with each target are not executed. However, /// a command line with a <plus-sign> ( '+' ) prefix shall be executed. - #[structopt(short, long)] + #[clap(short, long)] pub touch: bool, /// Change to the given directory before running. #[cfg(feature = "full")] - #[structopt(short = "C", long, parse(from_os_str))] + #[clap(short = 'C', long, value_parser)] pub directory: Option<PathBuf>, /// Target names or macro definitions. @@ -161,7 +161,7 @@ impl Args { .chain(env_makeflags.into_iter()) .chain(args); - Self::from_iter(args) + Self::parse_from(args) } pub fn from_env_and_args() -> Self { @@ -232,6 +232,12 @@ mod test { use super::*; #[test] + fn clap_validate() { + use clap::CommandFactory; + Args::command().debug_assert(); + } + + #[test] fn no_args() { let args: Vec<OsString> = vec!["makers".into()]; let args = Args::from_given_args_and_given_env(args.into_iter(), String::new()); |