From 27c119a252c01a621368624a9ab3e8efd9f18faf Mon Sep 17 00:00:00 2001 From: zseri Date: Sat, 27 Mar 2021 07:42:28 +0100 Subject: cargo fmt --- src/args.rs | 281 ++++++++++++++++++++++++++++++++++++------------------------ 1 file changed, 168 insertions(+), 113 deletions(-) (limited to 'src/args.rs') diff --git a/src/args.rs b/src/args.rs index 41ff4f0..e193294 100644 --- a/src/args.rs +++ b/src/args.rs @@ -20,7 +20,13 @@ 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", long = "file", visible_alias = "makefile", number_of_values = 1, parse(from_os_str))] + #[structopt( + short = "f", + long = "file", + visible_alias = "makefile", + number_of_values = 1, + parse(from_os_str) + )] pub makefile: Vec, /// Ignore error codes returned by invoked commands. @@ -33,7 +39,12 @@ pub struct Args { /// 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(short, long, overrides_with="keep-going", overrides_with="no-keep-going")] + #[structopt( + short, + long, + overrides_with = "keep-going", + overrides_with = "no-keep-going" + )] pub keep_going: bool, /// Write commands that would be executed on standard output, but do not execute them @@ -42,7 +53,12 @@ pub struct Args { /// However, lines with a ( '+' ) prefix shall be executed. In this mode, /// lines with an at-sign ( '@' ) character prefix shall be written to standard /// output. - #[structopt(short = "n", long, visible_alias = "just-print", visible_alias = "recon")] + #[structopt( + short = "n", + long, + visible_alias = "just-print", + visible_alias = "recon" + )] pub dry_run: bool, /// Write to standard output the complete set of macro definitions and target @@ -70,8 +86,14 @@ pub struct Args { /// reason). /// /// This shall be the default and the opposite of -k. - #[structopt(short = "S", long, visible_alias = "stop", hidden = true, - overrides_with="keep-going", overrides_with="no-keep-going")] + #[structopt( + short = "S", + long, + visible_alias = "stop", + hidden = true, + overrides_with = "keep-going", + overrides_with = "no-keep-going" + )] pub no_keep_going: bool, /// Do not write makefile command lines or touch messages to standard output before @@ -102,7 +124,10 @@ pub struct Args { } impl Args { - fn from_given_args_and_given_env(mut args: impl Iterator, env_makeflags: String) -> Args { + fn from_given_args_and_given_env( + mut args: impl Iterator, + env_makeflags: String, + ) -> Args { // POSIX spec says "Any options specified in the MAKEFLAGS environment variable // shall be evaluated before any options specified on the make utility command // line." @@ -114,14 +139,14 @@ impl Args { let makeflags_spaces = env_makeflags.contains(' '); let makeflags_leading_dash = env_makeflags.starts_with('-'); let makeflags_has_equals = env_makeflags.starts_with('='); - let makeflags_obviously_full = makeflags_spaces || makeflags_leading_dash || makeflags_has_equals; + let makeflags_obviously_full = + makeflags_spaces || makeflags_leading_dash || makeflags_has_equals; let env_makeflags = if makeflags_given && !makeflags_obviously_full { format!("-{}", env_makeflags) } else { env_makeflags }; - let env_makeflags = env_makeflags.split_whitespace() - .map(|x| OsString::from(x)); + let env_makeflags = env_makeflags.split_whitespace().map(|x| OsString::from(x)); // per the structopt docs, the first argument will be used as the binary name, // so we need to make sure it goes in before MAKEFLAGS let arg0 = args.next().unwrap_or_else(|| env!("CARGO_PKG_NAME").into()); @@ -139,11 +164,11 @@ impl Args { Self::from_given_args_and_given_env(args, env_makeflags) } - pub fn targets(&self) -> impl Iterator { + pub fn targets(&self) -> impl Iterator { self.targets_or_macros.iter().filter(|x| !x.contains('=')) } - pub fn macros(&self) -> impl Iterator { + pub fn macros(&self) -> impl Iterator { self.targets_or_macros.iter().filter(|x| x.contains('=')) } } @@ -156,80 +181,101 @@ mod test { fn no_args() { let args: Vec = vec!["makers".into()]; let args = Args::from_given_args_and_given_env(args.into_iter(), 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, - targets_or_macros: vec![], - }); + 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, + targets_or_macros: vec![], + } + ); } #[test] fn kitchen_sink_args() { let args = "makers -eiknpqrstf foo -f bruh bar baz=yeet"; - let args = Args::from_given_args_and_given_env(args.split_whitespace().map(OsString::from), String::new()); - assert_eq!(args, Args { - environment_overrides: true, - makefile: vec!["foo".into(), "bruh".into()], - ignore_errors: true, - keep_going: true, - dry_run: true, - print_everything: true, - question: true, - no_builtin_rules: true, - no_keep_going: false, - silent: true, - touch: true, - targets_or_macros: vec!["bar".into(), "baz=yeet".into()], - }); + let args = Args::from_given_args_and_given_env( + args.split_whitespace().map(OsString::from), + String::new(), + ); + assert_eq!( + args, + Args { + environment_overrides: true, + makefile: vec!["foo".into(), "bruh".into()], + ignore_errors: true, + keep_going: true, + dry_run: true, + print_everything: true, + question: true, + no_builtin_rules: true, + no_keep_going: false, + silent: true, + touch: true, + targets_or_macros: vec!["bar".into(), "baz=yeet".into()], + } + ); } #[test] fn keep_going_wrestling() { let args = "makers -kSkSkSSSkSkkSk -k -S -k -k -S -S -k"; - 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: true, - dry_run: false, - print_everything: false, - question: false, - no_builtin_rules: false, - no_keep_going: false, - silent: false, - touch: false, - targets_or_macros: vec![], - }); + 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: true, + dry_run: false, + print_everything: false, + question: false, + no_builtin_rules: false, + no_keep_going: false, + silent: false, + touch: false, + targets_or_macros: vec![], + } + ); } #[test] fn keep_going_wrestling_alt() { let args = "makers -kSkSkSSSkSkkSk -k -S -k -k -S -S -kS"; - 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: true, - silent: false, - touch: false, - targets_or_macros: vec![], - }); + 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: true, + silent: false, + touch: false, + targets_or_macros: vec![], + } + ); } #[test] @@ -237,20 +283,23 @@ mod test { let args = "makers"; let makeflags = "eiknp"; let args = Args::from_given_args_and_given_env(iter::once(args.into()), makeflags.into()); - assert_eq!(args, Args { - environment_overrides: true, - makefile: vec![], - ignore_errors: true, - keep_going: true, - dry_run: true, - print_everything: true, - question: false, - no_builtin_rules: false, - no_keep_going: false, - silent: false, - touch: false, - targets_or_macros: vec![], - }); + assert_eq!( + args, + Args { + environment_overrides: true, + makefile: vec![], + ignore_errors: true, + keep_going: true, + dry_run: true, + print_everything: true, + question: false, + no_builtin_rules: false, + no_keep_going: false, + silent: false, + touch: false, + targets_or_macros: vec![], + } + ); } #[test] @@ -258,20 +307,23 @@ mod test { let args = "makers"; let makeflags = "-i -knp"; let args = Args::from_given_args_and_given_env(iter::once(args.into()), makeflags.into()); - assert_eq!(args, Args { - environment_overrides: false, - makefile: vec![], - ignore_errors: true, - keep_going: true, - dry_run: true, - print_everything: true, - question: false, - no_builtin_rules: false, - no_keep_going: false, - silent: false, - touch: false, - targets_or_macros: vec![], - }); + assert_eq!( + args, + Args { + environment_overrides: false, + makefile: vec![], + ignore_errors: true, + keep_going: true, + dry_run: true, + print_everything: true, + question: false, + no_builtin_rules: false, + no_keep_going: false, + silent: false, + touch: false, + targets_or_macros: vec![], + } + ); } #[test] @@ -280,21 +332,24 @@ mod test { let args = "makers -eipqtSf foo -f bruh bar baz=yeet"; let args = Args::from_given_args_and_given_env( args.split_whitespace().map(OsString::from), - makeflags.into() + makeflags.into(), + ); + assert_eq!( + args, + Args { + environment_overrides: true, + makefile: vec!["foo".into(), "bruh".into()], + ignore_errors: true, + keep_going: false, + dry_run: true, + print_everything: true, + question: true, + no_builtin_rules: true, + no_keep_going: true, + silent: true, + touch: true, + targets_or_macros: vec!["foo=bar".into(), "bar".into(), "baz=yeet".into()], + } ); - assert_eq!(args, Args { - environment_overrides: true, - makefile: vec!["foo".into(), "bruh".into()], - ignore_errors: true, - keep_going: false, - dry_run: true, - print_everything: true, - question: true, - no_builtin_rules: true, - no_keep_going: true, - silent: true, - touch: true, - targets_or_macros: vec!["foo=bar".into(), "bar".into(), "baz=yeet".into()], - }); } } -- cgit v1.2.3