aboutsummaryrefslogtreecommitdiff
path: root/src/args.rs
diff options
context:
space:
mode:
authorzseri <zseri.devel@ytrizja.de>2021-03-27 07:42:28 +0100
committerzseri <zseri.devel@ytrizja.de>2021-03-27 07:42:28 +0100
commit27c119a252c01a621368624a9ab3e8efd9f18faf (patch)
tree89b303193d2d3ddf9aff2306de7e8d02449d7901 /src/args.rs
parent64790d036be21d9fc76bcec2102d2e1865ccd84f (diff)
downloadmakers-27c119a252c01a621368624a9ab3e8efd9f18faf.tar.gz
makers-27c119a252c01a621368624a9ab3e8efd9f18faf.zip
cargo fmt
Diffstat (limited to 'src/args.rs')
-rw-r--r--src/args.rs281
1 files changed, 168 insertions, 113 deletions
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<PathBuf>,
/// 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 <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", 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<Item=OsString>, env_makeflags: String) -> Args {
+ fn from_given_args_and_given_env(
+ mut args: impl Iterator<Item = OsString>,
+ 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<Item=&String> {
+ pub fn targets(&self) -> impl Iterator<Item = &String> {
self.targets_or_macros.iter().filter(|x| !x.contains('='))
}
- pub fn macros(&self) -> impl Iterator<Item=&String> {
+ pub fn macros(&self) -> impl Iterator<Item = &String> {
self.targets_or_macros.iter().filter(|x| x.contains('='))
}
}
@@ -156,80 +181,101 @@ mod 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());
- 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()],
- });
}
}