From f2f3e7dc4a448f9005ea1d0be9909cf25841bbec Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Fri, 14 Jun 2024 15:25:19 -0700 Subject: [PATCH 01/18] Inline CHOOSE_HELP --- src/config.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/config.rs b/src/config.rs index 34b72f3830..6e0a138c41 100644 --- a/src/config.rs +++ b/src/config.rs @@ -7,10 +7,6 @@ use { }, }; -const CHOOSE_HELP: &str = "Select one or more recipes to run using a binary chooser. \ - If `--chooser` is not passed the chooser defaults to the \ - value of $JUST_CHOOSER, falling back to `fzf`"; - #[derive(Debug, PartialEq)] pub(crate) struct Config { pub(crate) check: bool, @@ -356,7 +352,15 @@ impl Config { .action(ArgAction::SetTrue) .help("Print changelog"), ) - .arg(Arg::new(cmd::CHOOSE).long("choose").action(ArgAction::SetTrue).help(CHOOSE_HELP)) + .arg( + Arg::new(cmd::CHOOSE) + .long("choose") + .action(ArgAction::SetTrue) + .help( + "Select one or more recipes to run using a binary chooser. If `--chooser` is not \ + passed the chooser defaults to the value of $JUST_CHOOSER, falling back to `fzf`" + ) + ) .arg( Arg::new(cmd::COMMAND) .long("command") From 848be7924022f455d6280fd07d8a9a990945c29b Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Fri, 14 Jun 2024 15:29:50 -0700 Subject: [PATCH 02/18] Wrap --yes arg --- src/config.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/config.rs b/src/config.rs index 6e0a138c41..61e36ff0e0 100644 --- a/src/config.rs +++ b/src/config.rs @@ -186,7 +186,12 @@ impl Config { .value_parser(PossibleValuesParser::new(arg::COMMAND_COLOR_VALUES)) .help("Echo recipe lines in "), ) - .arg(Arg::new(arg::YES).long("yes").action(ArgAction::SetTrue).help("Automatically confirm all recipes.")) + .arg( + Arg::new(arg::YES) + .long("yes") + .action(ArgAction::SetTrue) + .help("Automatically confirm all recipes."), + ) .arg( Arg::new(arg::DRY_RUN) .short('n') From a1f19c9e5ae782d397f89ca3e1a8f4066698432d Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Fri, 14 Jun 2024 15:30:20 -0700 Subject: [PATCH 03/18] Wrap config --- src/config.rs | 79 ++++++++++++++++++++++++++------------------------- 1 file changed, 41 insertions(+), 38 deletions(-) diff --git a/src/config.rs b/src/config.rs index 61e36ff0e0..82f911aec2 100644 --- a/src/config.rs +++ b/src/config.rs @@ -150,17 +150,20 @@ impl Config { .trailing_var_arg(true) .styles( Styles::styled() - .header(AnsiColor::Yellow.on_default()) - .usage(AnsiColor::Yellow.on_default()) - .literal(AnsiColor::Green.on_default()) - .placeholder(AnsiColor::Green.on_default()) + .header(AnsiColor::Yellow.on_default()) + .usage(AnsiColor::Yellow.on_default()) + .literal(AnsiColor::Green.on_default()) + .placeholder(AnsiColor::Green.on_default()), ) .arg( Arg::new(arg::CHECK) .long("check") .action(ArgAction::SetTrue) .requires(cmd::FORMAT) - .help("Run `--fmt` in 'check' mode. Exits with 0 if justfile is formatted correctly. Exits with 1 and prints a diff if formatting is required."), + .help( + "Run `--fmt` in 'check' mode. Exits with 0 if justfile is formatted correctly. \ + Exits with 1 and prints a diff if formatting is required.", + ), ) .arg( Arg::new(arg::CHOOSER) @@ -244,12 +247,12 @@ impl Config { .action(ArgAction::SetTrue) .help("Don't show aliases in list"), ) - .arg ( + .arg( Arg::new(arg::NO_DEPS) .long("no-deps") .alias("no-dependencies") .action(ArgAction::SetTrue) - .help("Don't run recipe dependencies") + .help("Don't run recipe dependencies"), ) .arg( Arg::new(arg::NO_DOTENV) @@ -363,8 +366,8 @@ impl Config { .action(ArgAction::SetTrue) .help( "Select one or more recipes to run using a binary chooser. If `--chooser` is not \ - passed the chooser defaults to the value of $JUST_CHOOSER, falling back to `fzf`" - ) + passed the chooser defaults to the value of $JUST_CHOOSER, falling back to `fzf`", + ), ) .arg( Arg::new(cmd::COMMAND) @@ -436,10 +439,10 @@ impl Config { ) .arg( Arg::new(cmd::GROUPS) - .long("groups") - .action(ArgAction::SetTrue) - .help("List recipe groups") - ) + .long("groups") + .action(ArgAction::SetTrue) + .help("List recipe groups"), + ) .arg( Arg::new(cmd::MAN) .long("man") @@ -481,7 +484,7 @@ impl Config { .long("dotenv-path") .action(ArgAction::Set) .value_parser(value_parser!(PathBuf)) - .help("Load as environment file instead of searching for one") + .help("Load as environment file instead of searching for one"), ) .group(ArgGroup::new("SUBCOMMAND").args(cmd::ALL)) .arg( @@ -490,30 +493,30 @@ impl Config { .action(ArgAction::Append) .help("Overrides and recipe(s) to run, defaulting to the first recipe in the justfile"), ) - .arg( - Arg::new(arg::GLOBAL_JUSTFILE) - .action(ArgAction::SetTrue) - .long("global-justfile") - .short('g') - .conflicts_with(arg::JUSTFILE) - .conflicts_with(arg::WORKING_DIRECTORY) - .help("Use global justfile") - ) - .arg( - Arg::new(arg::TIMESTAMP) - .action(ArgAction::SetTrue) - .long("timestamp") - .env("JUST_TIMESTAMP") - .help("Print recipe command timestamps") - ) - .arg( - Arg::new(arg::TIMESTAMP_FORMAT) - .action(ArgAction::Set) - .long("timestamp-format") - .env("JUST_TIMESTAMP_FORMAT") - .default_value("%H:%M:%S") - .help("Timestamp format string") - ) + .arg( + Arg::new(arg::GLOBAL_JUSTFILE) + .action(ArgAction::SetTrue) + .long("global-justfile") + .short('g') + .conflicts_with(arg::JUSTFILE) + .conflicts_with(arg::WORKING_DIRECTORY) + .help("Use global justfile"), + ) + .arg( + Arg::new(arg::TIMESTAMP) + .action(ArgAction::SetTrue) + .long("timestamp") + .env("JUST_TIMESTAMP") + .help("Print recipe command timestamps"), + ) + .arg( + Arg::new(arg::TIMESTAMP_FORMAT) + .action(ArgAction::Set) + .long("timestamp-format") + .env("JUST_TIMESTAMP_FORMAT") + .default_value("%H:%M:%S") + .help("Timestamp format string"), + ) } fn color_from_matches(matches: &ArgMatches) -> ConfigResult { From 75a28995ba858ece211977f13c188168c91992e2 Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Fri, 14 Jun 2024 15:30:50 -0700 Subject: [PATCH 04/18] Add environment variable for `--yes` --- src/config.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/config.rs b/src/config.rs index 82f911aec2..93952dfa35 100644 --- a/src/config.rs +++ b/src/config.rs @@ -192,6 +192,7 @@ impl Config { .arg( Arg::new(arg::YES) .long("yes") + .env("JUST_YES") .action(ArgAction::SetTrue) .help("Automatically confirm all recipes."), ) From 3d025e9aab6be64c87653da63113864671148b83 Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Fri, 14 Jun 2024 15:31:29 -0700 Subject: [PATCH 05/18] Add environment variable for `--dump-format` --- src/config.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/config.rs b/src/config.rs index 93952dfa35..ffca875f9e 100644 --- a/src/config.rs +++ b/src/config.rs @@ -208,6 +208,7 @@ impl Config { .arg( Arg::new(arg::DUMP_FORMAT) .long("dump-format") + .env("JUST_DUMP_FORMAT") .action(ArgAction::Set) .value_parser(PossibleValuesParser::new(arg::DUMP_FORMAT_VALUES)) .default_value(arg::DUMP_FORMAT_JUST) From 9908c186b9790c4c4bf3c5a53a08aff408bb09f4 Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Fri, 14 Jun 2024 15:31:56 -0700 Subject: [PATCH 06/18] Add environment variable for `--highlight` --- src/config.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/config.rs b/src/config.rs index ffca875f9e..bcb79c3d15 100644 --- a/src/config.rs +++ b/src/config.rs @@ -218,6 +218,7 @@ impl Config { .arg( Arg::new(arg::HIGHLIGHT) .long("highlight") + .env("JUST_HIGHLIGHT") .action(ArgAction::SetTrue) .help("Highlight echoed recipe lines in bold") .overrides_with(arg::NO_HIGHLIGHT), From 909797d6be0907e412d7a072aff1ce3eba33e487 Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Fri, 14 Jun 2024 15:32:19 -0700 Subject: [PATCH 07/18] Add environment variable for --list-heading --- src/config.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/config.rs b/src/config.rs index bcb79c3d15..7abd6476bd 100644 --- a/src/config.rs +++ b/src/config.rs @@ -226,6 +226,7 @@ impl Config { .arg( Arg::new(arg::LIST_HEADING) .long("list-heading") + .env("JUST_LIST_HEADING") .help("Print before list") .value_name("TEXT") .action(ArgAction::Set), From ccb5f7c9dd1043a3fdd87dccc58830aa538fd0fb Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Fri, 14 Jun 2024 15:32:44 -0700 Subject: [PATCH 08/18] Add environmnet variable for `--list-prefix` --- src/config.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/config.rs b/src/config.rs index 7abd6476bd..85defa395a 100644 --- a/src/config.rs +++ b/src/config.rs @@ -234,6 +234,7 @@ impl Config { .arg( Arg::new(arg::LIST_PREFIX) .long("list-prefix") + .env("JUST_LIST_PREFIX") .help("Print before each list item") .value_name("TEXT") .action(ArgAction::Set), From 619cc804f65c9b4b3f4936c00ac6d04d481583cc Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Fri, 14 Jun 2024 15:33:07 -0700 Subject: [PATCH 09/18] Add env for --list-submodules --- src/config.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/config.rs b/src/config.rs index 85defa395a..eb8b746ce6 100644 --- a/src/config.rs +++ b/src/config.rs @@ -242,6 +242,7 @@ impl Config { .arg( Arg::new(arg::LIST_SUBMODULES) .long("list-submodules") + .env("JUST_LIST_SUBMODULES") .help("List recipes in submodules") .action(ArgAction::SetTrue) .env("JUST_LIST_SUBMODULES"), From b27ce0688e35dab0423f7df859423f0ee0ce168f Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Fri, 14 Jun 2024 15:35:53 -0700 Subject: [PATCH 10/18] More environment variables --- src/config.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/config.rs b/src/config.rs index eb8b746ce6..770e5808c1 100644 --- a/src/config.rs +++ b/src/config.rs @@ -250,12 +250,14 @@ impl Config { .arg( Arg::new(arg::NO_ALIASES) .long("no-aliases") + .env("JUST_NO_ALIASES") .action(ArgAction::SetTrue) .help("Don't show aliases in list"), ) .arg( Arg::new(arg::NO_DEPS) .long("no-deps") + .env("JUST_NO_DEPS") .alias("no-dependencies") .action(ArgAction::SetTrue) .help("Don't run recipe dependencies"), @@ -263,12 +265,14 @@ impl Config { .arg( Arg::new(arg::NO_DOTENV) .long("no-dotenv") + .env("JUST_NO_DOTENV") .action(ArgAction::SetTrue) .help("Don't load `.env` file"), ) .arg( Arg::new(arg::NO_HIGHLIGHT) .long("no-highlight") + .env("JUST_NO_HIGHLIGHT") .action(ArgAction::SetTrue) .help("Don't highlight echoed recipe lines in bold") .overrides_with(arg::HIGHLIGHT), @@ -330,6 +334,7 @@ impl Config { .arg( Arg::new(arg::UNSORTED) .long("unsorted") + .env("JUST_UNSORTED") .short('u') .action(ArgAction::SetTrue) .help("Return list and summary entries in source order"), From f056191831ed698052e4d90432c71f6f1bf80364 Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Fri, 14 Jun 2024 15:36:31 -0700 Subject: [PATCH 11/18] Reorder --- src/config.rs | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/src/config.rs b/src/config.rs index 770e5808c1..b64606666a 100644 --- a/src/config.rs +++ b/src/config.rs @@ -196,6 +196,21 @@ impl Config { .action(ArgAction::SetTrue) .help("Automatically confirm all recipes."), ) + .arg( + Arg::new(arg::DOTENV_FILENAME) + .long("dotenv-filename") + .action(ArgAction::Set) + .help("Search for environment file named instead of `.env`") + .conflicts_with(arg::DOTENV_PATH), + ) + .arg( + Arg::new(arg::DOTENV_PATH) + .short('E') + .long("dotenv-path") + .action(ArgAction::Set) + .value_parser(value_parser!(PathBuf)) + .help("Load as environment file instead of searching for one"), + ) .arg( Arg::new(arg::DRY_RUN) .short('n') @@ -482,21 +497,6 @@ impl Config { .action(ArgAction::SetTrue) .help("List names of variables"), ) - .arg( - Arg::new(arg::DOTENV_FILENAME) - .long("dotenv-filename") - .action(ArgAction::Set) - .help("Search for environment file named instead of `.env`") - .conflicts_with(arg::DOTENV_PATH), - ) - .arg( - Arg::new(arg::DOTENV_PATH) - .short('E') - .long("dotenv-path") - .action(ArgAction::Set) - .value_parser(value_parser!(PathBuf)) - .help("Load as environment file instead of searching for one"), - ) .group(ArgGroup::new("SUBCOMMAND").args(cmd::ALL)) .arg( Arg::new(arg::ARGUMENTS) From e258fac2b40d9d69b96a009bbb2082799a6e6a97 Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Fri, 14 Jun 2024 15:37:11 -0700 Subject: [PATCH 12/18] Reorder --- src/config.rs | 48 ++++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/src/config.rs b/src/config.rs index b64606666a..05ff203d15 100644 --- a/src/config.rs +++ b/src/config.rs @@ -380,6 +380,30 @@ impl Config { .help("Use as working directory. --justfile must also be set") .requires(arg::JUSTFILE), ) + .arg( + Arg::new(arg::GLOBAL_JUSTFILE) + .action(ArgAction::SetTrue) + .long("global-justfile") + .short('g') + .conflicts_with(arg::JUSTFILE) + .conflicts_with(arg::WORKING_DIRECTORY) + .help("Use global justfile"), + ) + .arg( + Arg::new(arg::TIMESTAMP) + .action(ArgAction::SetTrue) + .long("timestamp") + .env("JUST_TIMESTAMP") + .help("Print recipe command timestamps"), + ) + .arg( + Arg::new(arg::TIMESTAMP_FORMAT) + .action(ArgAction::Set) + .long("timestamp-format") + .env("JUST_TIMESTAMP_FORMAT") + .default_value("%H:%M:%S") + .help("Timestamp format string"), + ) .arg( Arg::new(cmd::CHANGELOG) .long("changelog") @@ -504,30 +528,6 @@ impl Config { .action(ArgAction::Append) .help("Overrides and recipe(s) to run, defaulting to the first recipe in the justfile"), ) - .arg( - Arg::new(arg::GLOBAL_JUSTFILE) - .action(ArgAction::SetTrue) - .long("global-justfile") - .short('g') - .conflicts_with(arg::JUSTFILE) - .conflicts_with(arg::WORKING_DIRECTORY) - .help("Use global justfile"), - ) - .arg( - Arg::new(arg::TIMESTAMP) - .action(ArgAction::SetTrue) - .long("timestamp") - .env("JUST_TIMESTAMP") - .help("Print recipe command timestamps"), - ) - .arg( - Arg::new(arg::TIMESTAMP_FORMAT) - .action(ArgAction::Set) - .long("timestamp-format") - .env("JUST_TIMESTAMP_FORMAT") - .default_value("%H:%M:%S") - .help("Timestamp format string"), - ) } fn color_from_matches(matches: &ArgMatches) -> ConfigResult { From f1d0fc6a58a9508db143d39e6298c2a9a7170e42 Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Fri, 14 Jun 2024 15:44:02 -0700 Subject: [PATCH 13/18] Sort config args --- src/config.rs | 99 ++++++++++++++++++++++++++------------------------- 1 file changed, 50 insertions(+), 49 deletions(-) diff --git a/src/config.rs b/src/config.rs index 05ff203d15..662e6f4eb5 100644 --- a/src/config.rs +++ b/src/config.rs @@ -151,9 +151,9 @@ impl Config { .styles( Styles::styled() .header(AnsiColor::Yellow.on_default()) - .usage(AnsiColor::Yellow.on_default()) .literal(AnsiColor::Green.on_default()) - .placeholder(AnsiColor::Green.on_default()), + .placeholder(AnsiColor::Green.on_default()) + .usage(AnsiColor::Yellow.on_default()), ) .arg( Arg::new(arg::CHECK) @@ -172,6 +172,13 @@ impl Config { .action(ArgAction::Set) .help("Override binary invoked by `--choose`"), ) + .arg( + Arg::new(arg::CLEAR_SHELL_ARGS) + .long("clear-shell-args") + .action(ArgAction::SetTrue) + .overrides_with(arg::SHELL_ARG) + .help("Clear shell arguments"), + ) .arg( Arg::new(arg::COLOR) .long("color") @@ -189,13 +196,6 @@ impl Config { .value_parser(PossibleValuesParser::new(arg::COMMAND_COLOR_VALUES)) .help("Echo recipe lines in "), ) - .arg( - Arg::new(arg::YES) - .long("yes") - .env("JUST_YES") - .action(ArgAction::SetTrue) - .help("Automatically confirm all recipes."), - ) .arg( Arg::new(arg::DOTENV_FILENAME) .long("dotenv-filename") @@ -230,6 +230,15 @@ impl Config { .value_name("FORMAT") .help("Dump justfile as "), ) + .arg( + Arg::new(arg::GLOBAL_JUSTFILE) + .action(ArgAction::SetTrue) + .long("global-justfile") + .short('g') + .conflicts_with(arg::JUSTFILE) + .conflicts_with(arg::WORKING_DIRECTORY) + .help("Use global justfile"), + ) .arg( Arg::new(arg::HIGHLIGHT) .long("highlight") @@ -238,6 +247,15 @@ impl Config { .help("Highlight echoed recipe lines in bold") .overrides_with(arg::NO_HIGHLIGHT), ) + .arg( + Arg::new(arg::JUSTFILE) + .short('f') + .long("justfile") + .env("JUST_JUSTFILE") + .action(ArgAction::Set) + .value_parser(value_parser!(PathBuf)) + .help("Use as justfile"), + ) .arg( Arg::new(arg::LIST_HEADING) .long("list-heading") @@ -292,15 +310,6 @@ impl Config { .help("Don't highlight echoed recipe lines in bold") .overrides_with(arg::HIGHLIGHT), ) - .arg( - Arg::new(arg::JUSTFILE) - .short('f') - .long("justfile") - .env("JUST_JUSTFILE") - .action(ArgAction::Set) - .value_parser(value_parser!(PathBuf)) - .help("Use as justfile"), - ) .arg( Arg::new(arg::QUIET) .short('q') @@ -340,11 +349,19 @@ impl Config { .help("Invoke with the shell used to run recipe lines and backticks"), ) .arg( - Arg::new(arg::CLEAR_SHELL_ARGS) - .long("clear-shell-args") + Arg::new(arg::TIMESTAMP) .action(ArgAction::SetTrue) - .overrides_with(arg::SHELL_ARG) - .help("Clear shell arguments"), + .long("timestamp") + .env("JUST_TIMESTAMP") + .help("Print recipe command timestamps"), + ) + .arg( + Arg::new(arg::TIMESTAMP_FORMAT) + .action(ArgAction::Set) + .long("timestamp-format") + .env("JUST_TIMESTAMP_FORMAT") + .default_value("%H:%M:%S") + .help("Timestamp format string"), ) .arg( Arg::new(arg::UNSORTED) @@ -381,28 +398,11 @@ impl Config { .requires(arg::JUSTFILE), ) .arg( - Arg::new(arg::GLOBAL_JUSTFILE) - .action(ArgAction::SetTrue) - .long("global-justfile") - .short('g') - .conflicts_with(arg::JUSTFILE) - .conflicts_with(arg::WORKING_DIRECTORY) - .help("Use global justfile"), - ) - .arg( - Arg::new(arg::TIMESTAMP) + Arg::new(arg::YES) + .long("yes") + .env("JUST_YES") .action(ArgAction::SetTrue) - .long("timestamp") - .env("JUST_TIMESTAMP") - .help("Print recipe command timestamps"), - ) - .arg( - Arg::new(arg::TIMESTAMP_FORMAT) - .action(ArgAction::Set) - .long("timestamp-format") - .env("JUST_TIMESTAMP_FORMAT") - .default_value("%H:%M:%S") - .help("Timestamp format string"), + .help("Automatically confirm all recipes."), ) .arg( Arg::new(cmd::CHANGELOG) @@ -457,6 +457,7 @@ impl Config { .arg( Arg::new(cmd::EVALUATE) .long("evaluate") + .alias("eval") .action(ArgAction::SetTrue) .help( "Evaluate and print all variables. If a variable name is given as an argument, only \ @@ -470,6 +471,12 @@ impl Config { .action(ArgAction::SetTrue) .help("Format and overwrite justfile"), ) + .arg( + Arg::new(cmd::GROUPS) + .long("groups") + .action(ArgAction::SetTrue) + .help("List recipe groups"), + ) .arg( Arg::new(cmd::INIT) .long("init") @@ -487,12 +494,6 @@ impl Config { .conflicts_with(arg::ARGUMENTS) .help("List available recipes"), ) - .arg( - Arg::new(cmd::GROUPS) - .long("groups") - .action(ArgAction::SetTrue) - .help("List recipe groups"), - ) .arg( Arg::new(cmd::MAN) .long("man") From 5ee32cb5b3c6889b61fe8e90a6754ef143f8dae6 Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Fri, 14 Jun 2024 15:51:30 -0700 Subject: [PATCH 14/18] Use result aliases --- src/config.rs | 2 +- src/function.rs | 143 +++++++++++++++++++++++----------------------- src/subcommand.rs | 26 ++++----- 3 files changed, 82 insertions(+), 89 deletions(-) diff --git a/src/config.rs b/src/config.rs index 662e6f4eb5..2b78cfc851 100644 --- a/src/config.rs +++ b/src/config.rs @@ -804,7 +804,7 @@ impl Config { }) } - pub(crate) fn require_unstable(&self, message: &str) -> Result<(), Error<'static>> { + pub(crate) fn require_unstable(&self, message: &str) -> RunResult<'static> { if self.unstable { Ok(()) } else { diff --git a/src/function.rs b/src/function.rs index 206faf8c5a..9d3ead8973 100644 --- a/src/function.rs +++ b/src/function.rs @@ -10,14 +10,16 @@ use { Function::*, }; +type FunctionResult = Result; + pub(crate) enum Function { - Nullary(fn(Context) -> Result), - Unary(fn(Context, &str) -> Result), - UnaryOpt(fn(Context, &str, Option<&str>) -> Result), - UnaryPlus(fn(Context, &str, &[String]) -> Result), - Binary(fn(Context, &str, &str) -> Result), - BinaryPlus(fn(Context, &str, &str, &[String]) -> Result), - Ternary(fn(Context, &str, &str, &str) -> Result), + Nullary(fn(Context) -> FunctionResult), + Unary(fn(Context, &str) -> FunctionResult), + UnaryOpt(fn(Context, &str, Option<&str>) -> FunctionResult), + UnaryPlus(fn(Context, &str, &[String]) -> FunctionResult), + Binary(fn(Context, &str, &str) -> FunctionResult), + BinaryPlus(fn(Context, &str, &str, &[String]) -> FunctionResult), + Ternary(fn(Context, &str, &str, &str) -> FunctionResult), } pub(crate) struct Context<'src: 'run, 'run> { @@ -119,7 +121,7 @@ impl Function { } } -fn absolute_path(context: Context, path: &str) -> Result { +fn absolute_path(context: Context, path: &str) -> FunctionResult { let abs_path_unchecked = context .evaluator .context @@ -136,7 +138,7 @@ fn absolute_path(context: Context, path: &str) -> Result { } } -fn append(_context: Context, suffix: &str, s: &str) -> Result { +fn append(_context: Context, suffix: &str, s: &str) -> FunctionResult { Ok( s.split_whitespace() .map(|s| format!("{s}{suffix}")) @@ -145,15 +147,15 @@ fn append(_context: Context, suffix: &str, s: &str) -> Result { ) } -fn arch(_context: Context) -> Result { +fn arch(_context: Context) -> FunctionResult { Ok(target::arch().to_owned()) } -fn blake3(_context: Context, s: &str) -> Result { +fn blake3(_context: Context, s: &str) -> FunctionResult { Ok(blake3::hash(s.as_bytes()).to_string()) } -fn blake3_file(context: Context, path: &str) -> Result { +fn blake3_file(context: Context, path: &str) -> FunctionResult { let path = context .evaluator .context @@ -167,7 +169,7 @@ fn blake3_file(context: Context, path: &str) -> Result { Ok(hasher.finalize().to_string()) } -fn canonicalize(_context: Context, path: &str) -> Result { +fn canonicalize(_context: Context, path: &str) -> FunctionResult { let canonical = std::fs::canonicalize(path).map_err(|err| format!("I/O error canonicalizing path: {err}"))?; @@ -179,7 +181,7 @@ fn canonicalize(_context: Context, path: &str) -> Result { }) } -fn capitalize(_context: Context, s: &str) -> Result { +fn capitalize(_context: Context, s: &str) -> FunctionResult { let mut capitalized = String::new(); for (i, c) in s.chars().enumerate() { if i == 0 { @@ -191,7 +193,7 @@ fn capitalize(_context: Context, s: &str) -> Result { Ok(capitalized) } -fn choose(_context: Context, n: &str, alphabet: &str) -> Result { +fn choose(_context: Context, n: &str, alphabet: &str) -> FunctionResult { if alphabet.is_empty() { return Err("empty alphabet".into()); } @@ -215,11 +217,11 @@ fn choose(_context: Context, n: &str, alphabet: &str) -> Result Ok((0..n).map(|_| alphabet.choose(&mut rng).unwrap()).collect()) } -fn clean(_context: Context, path: &str) -> Result { +fn clean(_context: Context, path: &str) -> FunctionResult { Ok(Path::new(path).lexiclean().to_str().unwrap().to_owned()) } -fn dir(name: &'static str, f: fn() -> Option) -> Result { +fn dir(name: &'static str, f: fn() -> Option) -> FunctionResult { match f() { Some(path) => path .as_os_str() @@ -235,7 +237,7 @@ fn dir(name: &'static str, f: fn() -> Option) -> Result } } -fn encode_uri_component(_context: Context, s: &str) -> Result { +fn encode_uri_component(_context: Context, s: &str) -> FunctionResult { static PERCENT_ENCODE: percent_encoding::AsciiSet = percent_encoding::NON_ALPHANUMERIC .remove(b'-') .remove(b'_') @@ -249,7 +251,7 @@ fn encode_uri_component(_context: Context, s: &str) -> Result { Ok(percent_encoding::utf8_percent_encode(s, &PERCENT_ENCODE).to_string()) } -fn env_var(context: Context, key: &str) -> Result { +fn env_var(context: Context, key: &str) -> FunctionResult { use std::env::VarError::*; if let Some(value) = context.evaluator.context.dotenv.get(key) { @@ -265,7 +267,7 @@ fn env_var(context: Context, key: &str) -> Result { } } -fn env_var_or_default(context: Context, key: &str, default: &str) -> Result { +fn env_var_or_default(context: Context, key: &str, default: &str) -> FunctionResult { use std::env::VarError::*; if let Some(value) = context.evaluator.context.dotenv.get(key) { @@ -281,39 +283,39 @@ fn env_var_or_default(context: Context, key: &str, default: &str) -> Result) -> Result { +fn env(context: Context, key: &str, default: Option<&str>) -> FunctionResult { match default { Some(val) => env_var_or_default(context, key, val), None => env_var(context, key), } } -fn error(_context: Context, message: &str) -> Result { +fn error(_context: Context, message: &str) -> FunctionResult { Err(message.to_owned()) } -fn extension(_context: Context, path: &str) -> Result { +fn extension(_context: Context, path: &str) -> FunctionResult { Utf8Path::new(path) .extension() .map(str::to_owned) .ok_or_else(|| format!("Could not extract extension from `{path}`")) } -fn file_name(_context: Context, path: &str) -> Result { +fn file_name(_context: Context, path: &str) -> FunctionResult { Utf8Path::new(path) .file_name() .map(str::to_owned) .ok_or_else(|| format!("Could not extract file name from `{path}`")) } -fn file_stem(_context: Context, path: &str) -> Result { +fn file_stem(_context: Context, path: &str) -> FunctionResult { Utf8Path::new(path) .file_stem() .map(str::to_owned) .ok_or_else(|| format!("Could not extract file stem from `{path}`")) } -fn invocation_directory(context: Context) -> Result { +fn invocation_directory(context: Context) -> FunctionResult { Platform::convert_native_path( &context.evaluator.context.search.working_directory, &context.evaluator.context.config.invocation_directory, @@ -321,7 +323,7 @@ fn invocation_directory(context: Context) -> Result { .map_err(|e| format!("Error getting shell path: {e}")) } -fn invocation_directory_native(context: Context) -> Result { +fn invocation_directory_native(context: Context) -> FunctionResult { context .evaluator .context @@ -342,11 +344,11 @@ fn invocation_directory_native(context: Context) -> Result { }) } -fn is_dependency(context: Context) -> Result { +fn is_dependency(context: Context) -> FunctionResult { Ok(context.evaluator.is_dependency.to_string()) } -fn prepend(_context: Context, prefix: &str, s: &str) -> Result { +fn prepend(_context: Context, prefix: &str, s: &str) -> FunctionResult { Ok( s.split_whitespace() .map(|s| format!("{prefix}{s}")) @@ -355,7 +357,7 @@ fn prepend(_context: Context, prefix: &str, s: &str) -> Result { ) } -fn join(_context: Context, base: &str, with: &str, and: &[String]) -> Result { +fn join(_context: Context, base: &str, with: &str, and: &[String]) -> FunctionResult { let mut result = Utf8Path::new(base).join(with); for arg in and { result.push(arg); @@ -363,7 +365,7 @@ fn join(_context: Context, base: &str, with: &str, and: &[String]) -> Result Result { +fn just_executable(_context: Context) -> FunctionResult { let exe_path = env::current_exe().map_err(|e| format!("Error getting current executable: {e}"))?; @@ -375,11 +377,11 @@ fn just_executable(_context: Context) -> Result { }) } -fn just_pid(_context: Context) -> Result { +fn just_pid(_context: Context) -> FunctionResult { Ok(std::process::id().to_string()) } -fn justfile(context: Context) -> Result { +fn justfile(context: Context) -> FunctionResult { context .evaluator .context @@ -395,7 +397,7 @@ fn justfile(context: Context) -> Result { }) } -fn justfile_directory(context: Context) -> Result { +fn justfile_directory(context: Context) -> FunctionResult { let justfile_directory = context .evaluator .context @@ -420,19 +422,19 @@ fn justfile_directory(context: Context) -> Result { }) } -fn kebabcase(_context: Context, s: &str) -> Result { +fn kebabcase(_context: Context, s: &str) -> FunctionResult { Ok(s.to_kebab_case()) } -fn lowercamelcase(_context: Context, s: &str) -> Result { +fn lowercamelcase(_context: Context, s: &str) -> FunctionResult { Ok(s.to_lower_camel_case()) } -fn lowercase(_context: Context, s: &str) -> Result { +fn lowercase(_context: Context, s: &str) -> FunctionResult { Ok(s.to_lowercase()) } -fn module_directory(context: Context) -> Result { +fn module_directory(context: Context) -> FunctionResult { context .evaluator .context @@ -459,7 +461,7 @@ fn module_directory(context: Context) -> Result { }) } -fn module_file(context: Context) -> Result { +fn module_file(context: Context) -> FunctionResult { context .evaluator .context @@ -478,27 +480,27 @@ fn module_file(context: Context) -> Result { }) } -fn num_cpus(_context: Context) -> Result { +fn num_cpus(_context: Context) -> FunctionResult { let num = num_cpus::get(); Ok(num.to_string()) } -fn os(_context: Context) -> Result { +fn os(_context: Context) -> FunctionResult { Ok(target::os().to_owned()) } -fn os_family(_context: Context) -> Result { +fn os_family(_context: Context) -> FunctionResult { Ok(target::family().to_owned()) } -fn parent_directory(_context: Context, path: &str) -> Result { +fn parent_directory(_context: Context, path: &str) -> FunctionResult { Utf8Path::new(path) .parent() .map(Utf8Path::to_string) .ok_or_else(|| format!("Could not extract parent directory from `{path}`")) } -fn path_exists(context: Context, path: &str) -> Result { +fn path_exists(context: Context, path: &str) -> FunctionResult { Ok( context .evaluator @@ -511,20 +513,15 @@ fn path_exists(context: Context, path: &str) -> Result { ) } -fn quote(_context: Context, s: &str) -> Result { +fn quote(_context: Context, s: &str) -> FunctionResult { Ok(format!("'{}'", s.replace('\'', "'\\''"))) } -fn replace(_context: Context, s: &str, from: &str, to: &str) -> Result { +fn replace(_context: Context, s: &str, from: &str, to: &str) -> FunctionResult { Ok(s.replace(from, to)) } -fn replace_regex( - _context: Context, - s: &str, - regex: &str, - replacement: &str, -) -> Result { +fn replace_regex(_context: Context, s: &str, regex: &str, replacement: &str) -> FunctionResult { Ok( Regex::new(regex) .map_err(|err| err.to_string())? @@ -533,7 +530,7 @@ fn replace_regex( ) } -fn sha256(_context: Context, s: &str) -> Result { +fn sha256(_context: Context, s: &str) -> FunctionResult { use sha2::{Digest, Sha256}; let mut hasher = Sha256::new(); hasher.update(s); @@ -541,7 +538,7 @@ fn sha256(_context: Context, s: &str) -> Result { Ok(format!("{hash:x}")) } -fn sha256_file(context: Context, path: &str) -> Result { +fn sha256_file(context: Context, path: &str) -> FunctionResult { use sha2::{Digest, Sha256}; let path = context .evaluator @@ -558,7 +555,7 @@ fn sha256_file(context: Context, path: &str) -> Result { Ok(format!("{hash:x}")) } -fn shell(context: Context, command: &str, args: &[String]) -> Result { +fn shell(context: Context, command: &str, args: &[String]) -> FunctionResult { let args = iter::once(command) .chain(args.iter().map(String::as_str)) .collect::>(); @@ -569,19 +566,19 @@ fn shell(context: Context, command: &str, args: &[String]) -> Result Result { +fn shoutykebabcase(_context: Context, s: &str) -> FunctionResult { Ok(s.to_shouty_kebab_case()) } -fn shoutysnakecase(_context: Context, s: &str) -> Result { +fn shoutysnakecase(_context: Context, s: &str) -> FunctionResult { Ok(s.to_shouty_snake_case()) } -fn snakecase(_context: Context, s: &str) -> Result { +fn snakecase(_context: Context, s: &str) -> FunctionResult { Ok(s.to_snake_case()) } -fn source_directory(context: Context) -> Result { +fn source_directory(context: Context) -> FunctionResult { context .evaluator .context @@ -602,7 +599,7 @@ fn source_directory(context: Context) -> Result { }) } -fn source_file(context: Context) -> Result { +fn source_file(context: Context) -> FunctionResult { context .evaluator .context @@ -621,51 +618,51 @@ fn source_file(context: Context) -> Result { }) } -fn titlecase(_context: Context, s: &str) -> Result { +fn titlecase(_context: Context, s: &str) -> FunctionResult { Ok(s.to_title_case()) } -fn trim(_context: Context, s: &str) -> Result { +fn trim(_context: Context, s: &str) -> FunctionResult { Ok(s.trim().to_owned()) } -fn trim_end(_context: Context, s: &str) -> Result { +fn trim_end(_context: Context, s: &str) -> FunctionResult { Ok(s.trim_end().to_owned()) } -fn trim_end_match(_context: Context, s: &str, pat: &str) -> Result { +fn trim_end_match(_context: Context, s: &str, pat: &str) -> FunctionResult { Ok(s.strip_suffix(pat).unwrap_or(s).to_owned()) } -fn trim_end_matches(_context: Context, s: &str, pat: &str) -> Result { +fn trim_end_matches(_context: Context, s: &str, pat: &str) -> FunctionResult { Ok(s.trim_end_matches(pat).to_owned()) } -fn trim_start(_context: Context, s: &str) -> Result { +fn trim_start(_context: Context, s: &str) -> FunctionResult { Ok(s.trim_start().to_owned()) } -fn trim_start_match(_context: Context, s: &str, pat: &str) -> Result { +fn trim_start_match(_context: Context, s: &str, pat: &str) -> FunctionResult { Ok(s.strip_prefix(pat).unwrap_or(s).to_owned()) } -fn trim_start_matches(_context: Context, s: &str, pat: &str) -> Result { +fn trim_start_matches(_context: Context, s: &str, pat: &str) -> FunctionResult { Ok(s.trim_start_matches(pat).to_owned()) } -fn uppercamelcase(_context: Context, s: &str) -> Result { +fn uppercamelcase(_context: Context, s: &str) -> FunctionResult { Ok(s.to_upper_camel_case()) } -fn uppercase(_context: Context, s: &str) -> Result { +fn uppercase(_context: Context, s: &str) -> FunctionResult { Ok(s.to_uppercase()) } -fn uuid(_context: Context) -> Result { +fn uuid(_context: Context) -> FunctionResult { Ok(uuid::Uuid::new_v4().to_string()) } -fn without_extension(_context: Context, path: &str) -> Result { +fn without_extension(_context: Context, path: &str) -> FunctionResult { let parent = Utf8Path::new(path) .parent() .ok_or_else(|| format!("Could not extract parent from `{path}`"))?; @@ -679,7 +676,7 @@ fn without_extension(_context: Context, path: &str) -> Result { /// Check whether a string processes properly as semver (e.x. "0.1.0") /// and matches a given semver requirement (e.x. ">=0.1.0") -fn semver_matches(_context: Context, version: &str, requirement: &str) -> Result { +fn semver_matches(_context: Context, version: &str, requirement: &str) -> FunctionResult { Ok( requirement .parse::() diff --git a/src/subcommand.rs b/src/subcommand.rs index a595249ae8..9b9a2463b0 100644 --- a/src/subcommand.rs +++ b/src/subcommand.rs @@ -42,11 +42,7 @@ pub(crate) enum Subcommand { } impl Subcommand { - pub(crate) fn execute<'src>( - &self, - config: &Config, - loader: &'src Loader, - ) -> Result<(), Error<'src>> { + pub(crate) fn execute<'src>(&self, config: &Config, loader: &'src Loader) -> RunResult<'src> { use Subcommand::*; match self { @@ -107,7 +103,7 @@ impl Subcommand { loader: &'src Loader, arguments: &[String], overrides: &BTreeMap, - ) -> Result<(), Error<'src>> { + ) -> RunResult<'src> { if matches!( config.search_config, SearchConfig::FromInvocationDirectory | SearchConfig::FromSearchDirectory { .. } @@ -192,7 +188,7 @@ impl Subcommand { config: &Config, loader: &'src Loader, search: &Search, - ) -> Result, Error<'src>> { + ) -> RunResult<'src, Compilation<'src>> { let compilation = Compiler::compile(config.unstable, loader, &search.justfile)?; if config.verbosity.loud() { @@ -214,7 +210,7 @@ impl Subcommand { search: &Search, overrides: &BTreeMap, chooser: Option<&str>, - ) -> Result<(), Error<'src>> { + ) -> RunResult<'src> { let mut recipes = Vec::<&Recipe>::new(); let mut stack = vec![justfile]; while let Some(module) = stack.pop() { @@ -304,7 +300,7 @@ impl Subcommand { Ok(()) } - fn dump(config: &Config, ast: &Ast, justfile: &Justfile) -> Result<(), Error<'static>> { + fn dump(config: &Config, ast: &Ast, justfile: &Justfile) -> RunResult<'static> { match config.dump_format { DumpFormat::Json => { serde_json::to_writer(io::stdout(), justfile) @@ -316,7 +312,7 @@ impl Subcommand { Ok(()) } - fn edit(search: &Search) -> Result<(), Error<'static>> { + fn edit(search: &Search) -> RunResult<'static> { let editor = env::var_os("VISUAL") .or_else(|| env::var_os("EDITOR")) .unwrap_or_else(|| "vim".into()); @@ -338,7 +334,7 @@ impl Subcommand { Ok(()) } - fn format(config: &Config, search: &Search, src: &str, ast: &Ast) -> Result<(), Error<'static>> { + fn format(config: &Config, search: &Search, src: &str, ast: &Ast) -> RunResult<'static> { config.require_unstable("The `--fmt` command is currently unstable.")?; let formatted = ast.to_string(); @@ -383,7 +379,7 @@ impl Subcommand { Ok(()) } - fn init(config: &Config) -> Result<(), Error<'static>> { + fn init(config: &Config) -> RunResult<'static> { let search = Search::init(&config.search_config, &config.invocation_directory)?; if search.justfile.is_file() { @@ -403,7 +399,7 @@ impl Subcommand { } } - fn man() -> Result<(), Error<'static>> { + fn man() -> RunResult<'static> { let mut buffer = Vec::::new(); Man::new(Config::app()) @@ -423,7 +419,7 @@ impl Subcommand { Ok(()) } - fn list(config: &Config, mut module: &Justfile, path: &ModulePath) -> Result<(), Error<'static>> { + fn list(config: &Config, mut module: &Justfile, path: &ModulePath) -> RunResult<'static> { for name in &path.path { module = module .modules @@ -585,7 +581,7 @@ impl Subcommand { config: &Config, mut module: &Justfile<'src>, path: &ModulePath, - ) -> Result<(), Error<'src>> { + ) -> RunResult<'src> { for name in &path.path[0..path.path.len() - 1] { module = module .modules From d37cd37fa3e40a42c6b54836cb2681dde91c8ec7 Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Fri, 14 Jun 2024 15:55:01 -0700 Subject: [PATCH 15/18] Use FunctionResult --- src/function.rs | 2 -- src/lib.rs | 9 +++++---- src/platform.rs | 8 ++++---- src/platform_interface.rs | 2 +- src/summary.rs | 2 +- src/thunk.rs | 14 +++++++------- 6 files changed, 18 insertions(+), 19 deletions(-) diff --git a/src/function.rs b/src/function.rs index 9d3ead8973..922676228e 100644 --- a/src/function.rs +++ b/src/function.rs @@ -10,8 +10,6 @@ use { Function::*, }; -type FunctionResult = Result; - pub(crate) enum Function { Nullary(fn(Context) -> FunctionResult), Unary(fn(Context, &str) -> FunctionResult), diff --git a/src/lib.rs b/src/lib.rs index 5275cecf91..b5b17f4e65 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -86,10 +86,11 @@ pub use crate::run::run; #[doc(hidden)] pub use unindent::unindent; -pub(crate) type CompileResult<'a, T = ()> = Result>; -pub(crate) type ConfigResult = Result; -pub(crate) type RunResult<'a, T = ()> = Result>; -pub(crate) type SearchResult = Result; +type CompileResult<'a, T = ()> = Result>; +type ConfigResult = Result; +type FunctionResult = Result; +type RunResult<'a, T = ()> = Result>; +type SearchResult = Result; #[cfg(test)] #[macro_use] diff --git a/src/platform.rs b/src/platform.rs index 36be7fc743..01bf74b584 100644 --- a/src/platform.rs +++ b/src/platform.rs @@ -19,7 +19,7 @@ impl PlatformInterface for Platform { Ok(cmd) } - fn set_execute_permission(path: &Path) -> Result<(), io::Error> { + fn set_execute_permission(path: &Path) -> io::Result<()> { use std::os::unix::fs::PermissionsExt; // get current permissions @@ -38,7 +38,7 @@ impl PlatformInterface for Platform { exit_status.signal() } - fn convert_native_path(_working_directory: &Path, path: &Path) -> Result { + fn convert_native_path(_working_directory: &Path, path: &Path) -> FunctionResult { path .to_str() .map(str::to_string) @@ -85,7 +85,7 @@ impl PlatformInterface for Platform { Ok(cmd) } - fn set_execute_permission(_path: &Path) -> Result<(), io::Error> { + fn set_execute_permission(_path: &Path) -> io::Result<()> { // it is not necessary to set an execute permission on a script on windows, so // this is a nop Ok(()) @@ -97,7 +97,7 @@ impl PlatformInterface for Platform { None } - fn convert_native_path(working_directory: &Path, path: &Path) -> Result { + fn convert_native_path(working_directory: &Path, path: &Path) -> FunctionResult { // Translate path from windows style to unix style let mut cygpath = Command::new("cygpath"); cygpath.current_dir(working_directory); diff --git a/src/platform_interface.rs b/src/platform_interface.rs index 4a984ffb5d..3a489f9c51 100644 --- a/src/platform_interface.rs +++ b/src/platform_interface.rs @@ -17,5 +17,5 @@ pub(crate) trait PlatformInterface { fn signal_from_exit_status(exit_status: ExitStatus) -> Option; /// Translate a path from a "native" path to a path the interpreter expects - fn convert_native_path(working_directory: &Path, path: &Path) -> Result; + fn convert_native_path(working_directory: &Path, path: &Path) -> FunctionResult; } diff --git a/src/summary.rs b/src/summary.rs index 472feb04fe..65a28ba1f9 100644 --- a/src/summary.rs +++ b/src/summary.rs @@ -25,7 +25,7 @@ mod full { }; } -pub fn summary(path: &Path) -> Result, io::Error> { +pub fn summary(path: &Path) -> io::Result> { let loader = Loader::new(); match Compiler::compile(false, &loader, path) { diff --git a/src/thunk.rs b/src/thunk.rs index 2ab203abb9..82668998a5 100644 --- a/src/thunk.rs +++ b/src/thunk.rs @@ -6,42 +6,42 @@ pub(crate) enum Thunk<'src> { Nullary { name: Name<'src>, #[derivative(Debug = "ignore", PartialEq = "ignore")] - function: fn(function::Context) -> Result, + function: fn(function::Context) -> FunctionResult, }, Unary { name: Name<'src>, #[derivative(Debug = "ignore", PartialEq = "ignore")] - function: fn(function::Context, &str) -> Result, + function: fn(function::Context, &str) -> FunctionResult, arg: Box>, }, UnaryOpt { name: Name<'src>, #[derivative(Debug = "ignore", PartialEq = "ignore")] - function: fn(function::Context, &str, Option<&str>) -> Result, + function: fn(function::Context, &str, Option<&str>) -> FunctionResult, args: (Box>, Box>>), }, UnaryPlus { name: Name<'src>, #[derivative(Debug = "ignore", PartialEq = "ignore")] - function: fn(function::Context, &str, &[String]) -> Result, + function: fn(function::Context, &str, &[String]) -> FunctionResult, args: (Box>, Vec>), }, Binary { name: Name<'src>, #[derivative(Debug = "ignore", PartialEq = "ignore")] - function: fn(function::Context, &str, &str) -> Result, + function: fn(function::Context, &str, &str) -> FunctionResult, args: [Box>; 2], }, BinaryPlus { name: Name<'src>, #[derivative(Debug = "ignore", PartialEq = "ignore")] - function: fn(function::Context, &str, &str, &[String]) -> Result, + function: fn(function::Context, &str, &str, &[String]) -> FunctionResult, args: ([Box>; 2], Vec>), }, Ternary { name: Name<'src>, #[derivative(Debug = "ignore", PartialEq = "ignore")] - function: fn(function::Context, &str, &str, &str) -> Result, + function: fn(function::Context, &str, &str, &str) -> FunctionResult, args: [Box>; 3], }, } From ac4da70d7227871e558b058f99b693c841980cd3 Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Fri, 14 Jun 2024 15:56:54 -0700 Subject: [PATCH 16/18] Use more aliases --- src/config.rs | 2 +- src/platform_interface.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/config.rs b/src/config.rs index 2b78cfc851..c6b22c56e7 100644 --- a/src/config.rs +++ b/src/config.rs @@ -814,7 +814,7 @@ impl Config { } } - pub(crate) fn run(self, loader: &Loader) -> Result<(), Error> { + pub(crate) fn run(self, loader: &Loader) -> RunResult { if let Err(error) = InterruptHandler::install(self.verbosity) { warn!("Failed to set CTRL-C handler: {error}"); } diff --git a/src/platform_interface.rs b/src/platform_interface.rs index 3a489f9c51..463f6650a6 100644 --- a/src/platform_interface.rs +++ b/src/platform_interface.rs @@ -10,7 +10,7 @@ pub(crate) trait PlatformInterface { ) -> Result; /// Set the execute permission on the file pointed to by `path` - fn set_execute_permission(path: &Path) -> Result<(), io::Error>; + fn set_execute_permission(path: &Path) -> io::Result<()>; /// Extract the signal from a process exit status, if it was terminated by a /// signal From bbd7ad8a092874df3e8b8b6db9a92d0c701cb441 Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Fri, 14 Jun 2024 15:59:51 -0700 Subject: [PATCH 17/18] Sort commands --- src/config.rs | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/src/config.rs b/src/config.rs index c6b22c56e7..0aaeaea96b 100644 --- a/src/config.rs +++ b/src/config.rs @@ -708,28 +708,10 @@ impl Config { } } else if let Some(&shell) = matches.get_one::(cmd::COMPLETIONS) { Subcommand::Completions { shell } - } else if matches.get_flag(cmd::EDIT) { - Subcommand::Edit - } else if matches.get_flag(cmd::SUMMARY) { - Subcommand::Summary } else if matches.get_flag(cmd::DUMP) { Subcommand::Dump - } else if matches.get_flag(cmd::FORMAT) { - Subcommand::Format - } else if matches.get_flag(cmd::INIT) { - Subcommand::Init - } else if let Some(path) = matches.get_many::(cmd::LIST) { - Subcommand::List { - path: Self::parse_module_path(path)?, - } - } else if matches.get_flag(cmd::GROUPS) { - Subcommand::Groups - } else if matches.get_flag(cmd::MAN) { - Subcommand::Man - } else if let Some(path) = matches.get_many::(cmd::SHOW) { - Subcommand::Show { - path: Self::parse_module_path(path)?, - } + } else if matches.get_flag(cmd::EDIT) { + Subcommand::Edit } else if matches.get_flag(cmd::EVALUATE) { if positional.arguments.len() > 1 { return Err(ConfigError::SubcommandArguments { @@ -746,6 +728,24 @@ impl Config { variable: positional.arguments.into_iter().next(), overrides, } + } else if matches.get_flag(cmd::FORMAT) { + Subcommand::Format + } else if matches.get_flag(cmd::GROUPS) { + Subcommand::Groups + } else if matches.get_flag(cmd::INIT) { + Subcommand::Init + } else if let Some(path) = matches.get_many::(cmd::LIST) { + Subcommand::List { + path: Self::parse_module_path(path)?, + } + } else if matches.get_flag(cmd::MAN) { + Subcommand::Man + } else if let Some(path) = matches.get_many::(cmd::SHOW) { + Subcommand::Show { + path: Self::parse_module_path(path)?, + } + } else if matches.get_flag(cmd::SUMMARY) { + Subcommand::Summary } else if matches.get_flag(cmd::VARIABLES) { Subcommand::Variables } else { From 9ab9b35737fc4d2fe5dd38c2f14d45c424d58e64 Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Fri, 14 Jun 2024 16:03:06 -0700 Subject: [PATCH 18/18] Inline arguments --- src/config.rs | 43 ++++++++++++++++--------------------------- 1 file changed, 16 insertions(+), 27 deletions(-) diff --git a/src/config.rs b/src/config.rs index 0aaeaea96b..0e8f3d49e8 100644 --- a/src/config.rs +++ b/src/config.rs @@ -635,17 +635,6 @@ impl Config { } pub(crate) fn from_matches(matches: &ArgMatches) -> ConfigResult { - let invocation_directory = env::current_dir().context(config_error::CurrentDirContext)?; - - let verbosity = if matches.get_flag(arg::QUIET) { - Verbosity::Quiet - } else { - Verbosity::from_flag_occurrences(matches.get_count(arg::VERBOSE)) - }; - - let color = Self::color_from_matches(matches)?; - let command_color = Self::command_color_from_matches(matches)?; - let mut overrides = BTreeMap::new(); if let Some(mut values) = matches.get_many::(arg::SET) { while let (Some(k), Some(v)) = (values.next(), values.next()) { @@ -755,20 +744,10 @@ impl Config { } }; - let shell_args = if matches.get_flag(arg::CLEAR_SHELL_ARGS) { - Some(Vec::new()) - } else { - matches - .get_many::(arg::SHELL_ARG) - .map(|s| s.map(Into::into).collect()) - }; - - let unstable = matches.get_flag(arg::UNSTABLE); - Ok(Self { check: matches.get_flag(arg::CHECK), - color, - command_color, + color: Self::color_from_matches(matches)?, + command_color: Self::command_color_from_matches(matches)?, dotenv_filename: matches .get_one::(arg::DOTENV_FILENAME) .map(Into::into), @@ -776,7 +755,7 @@ impl Config { dry_run: matches.get_flag(arg::DRY_RUN), dump_format: Self::dump_format_from_matches(matches)?, highlight: !matches.get_flag(arg::NO_HIGHLIGHT), - invocation_directory, + invocation_directory: env::current_dir().context(config_error::CurrentDirContext)?, list_heading: matches .get_one::(arg::LIST_HEADING) .map_or_else(|| "Available recipes:\n".into(), Into::into), @@ -789,7 +768,13 @@ impl Config { no_dependencies: matches.get_flag(arg::NO_DEPS), search_config, shell: matches.get_one::(arg::SHELL).map(Into::into), - shell_args, + shell_args: if matches.get_flag(arg::CLEAR_SHELL_ARGS) { + Some(Vec::new()) + } else { + matches + .get_many::(arg::SHELL_ARG) + .map(|s| s.map(Into::into).collect()) + }, shell_command: matches.get_flag(arg::SHELL_COMMAND), subcommand, timestamp: matches.get_flag(arg::TIMESTAMP), @@ -798,8 +783,12 @@ impl Config { .unwrap() .into(), unsorted: matches.get_flag(arg::UNSORTED), - unstable, - verbosity, + unstable: matches.get_flag(arg::UNSTABLE), + verbosity: if matches.get_flag(arg::QUIET) { + Verbosity::Quiet + } else { + Verbosity::from_flag_occurrences(matches.get_count(arg::VERBOSE)) + }, yes: matches.get_flag(arg::YES), }) }