From d0872a6f4c699b5e4e3401e46aa0b24b4b3997a0 Mon Sep 17 00:00:00 2001 From: Melody Horn Date: Wed, 13 Nov 2024 20:05:55 -0700 Subject: =?UTF-8?q?pretend=20to=20support=20GNU=E2=80=99s=20--no-print-dir?= =?UTF-8?q?ectory?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/args.rs | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 74 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/args.rs b/src/args.rs index baddb47..558a0b1 100644 --- a/src/args.rs +++ b/src/args.rs @@ -121,6 +121,18 @@ pub struct Args { #[clap(short = 'C', long, value_parser)] pub directory: Option, + /// Print the working directory when starting. + // TODO implement + // TODO automatically with -C or recursion or decide that this is a bad GNU feature + #[cfg(feature = "full")] + #[clap(short = 'w', long, overrides_with = "print_directory", overrides_with = "no_print_directory")] + pub print_directory: bool, + + /// Do not print the working directory when starting, even when running with -C or recursively. + #[cfg(feature = "full")] + #[clap(long, overrides_with = "print_directory", overrides_with = "no_print_directory")] + pub no_print_directory: bool, + /// Target names or macro definitions. /// /// If no target is specified, while make is processing the makefiles, the first @@ -221,6 +233,7 @@ impl Args { if self.touch { result.push('t'); } + // TODO decide whether or not print_directory should go here too result } } @@ -255,6 +268,10 @@ mod test { touch: false, #[cfg(feature = "full")] directory: None, + #[cfg(feature = "full")] + print_directory: false, + #[cfg(feature = "full")] + no_print_directory: false, targets_or_macros: vec![], } ); @@ -262,7 +279,7 @@ mod test { #[test] fn kitchen_sink_args() { - let args = "makers -eiknpqrstf foo -f bruh bar baz=yeet"; + let args = "makers -eiknpqrstwf foo -f bruh bar baz=yeet"; let args = Args::from_given_args_and_given_env( args.split_whitespace().map(OsString::from), String::new(), @@ -283,6 +300,10 @@ mod test { touch: true, #[cfg(feature = "full")] directory: None, + #[cfg(feature = "full")] + print_directory: true, + #[cfg(feature = "full")] + no_print_directory: false, targets_or_macros: vec!["bar".into(), "baz=yeet".into()], } ); @@ -311,6 +332,10 @@ mod test { touch: false, #[cfg(feature = "full")] directory: None, + #[cfg(feature = "full")] + print_directory: false, + #[cfg(feature = "full")] + no_print_directory: false, targets_or_macros: vec![], } ); @@ -339,6 +364,42 @@ mod test { touch: false, #[cfg(feature = "full")] directory: None, + #[cfg(feature = "full")] + print_directory: false, + #[cfg(feature = "full")] + no_print_directory: false, + targets_or_macros: vec![], + } + ); + } + + #[test] + fn print_directory_wrestling() { + let args = "makers -w --no-print-directory -w -w --no-print-directory --no-print-directory -w --no-print-directory"; + let args = Args::from_given_args_and_given_env( + args.split_whitespace().map(OsString::from), + String::new(), + ); + assert_eq!( + args, + Args { + environment_overrides: false, + makefile: vec![], + ignore_errors: false, + keep_going: false, + dry_run: false, + print_everything: false, + question: false, + no_builtin_rules: false, + no_keep_going: false, + silent: false, + touch: false, + #[cfg(feature = "full")] + directory: None, + #[cfg(feature = "full")] + print_directory: false, + #[cfg(feature = "full")] + no_print_directory: true, targets_or_macros: vec![], } ); @@ -365,6 +426,10 @@ mod test { touch: false, #[cfg(feature = "full")] directory: None, + #[cfg(feature = "full")] + print_directory: false, + #[cfg(feature = "full")] + no_print_directory: false, targets_or_macros: vec![], } ); @@ -391,6 +456,10 @@ mod test { touch: false, #[cfg(feature = "full")] directory: None, + #[cfg(feature = "full")] + print_directory: false, + #[cfg(feature = "full")] + no_print_directory: false, targets_or_macros: vec![], } ); @@ -420,6 +489,10 @@ mod test { touch: true, #[cfg(feature = "full")] directory: None, + #[cfg(feature = "full")] + print_directory: false, + #[cfg(feature = "full")] + no_print_directory: false, targets_or_macros: vec!["foo=bar".into(), "bar".into(), "baz=yeet".into()], } ); -- cgit v1.2.3