summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNeal Harrington <ngharrington@users.noreply.github.com>2024-01-09 03:40:08 -0500
committerGitHub <noreply@github.com>2024-01-09 08:40:08 +0000
commitb66cce0f58cb484e4625fffdd22b3a87ac2a0129 (patch)
treead7f7c727e21de7722c4ee83e334e76c85fbb309
parent541e78104c6d9030f35751bcf6c59e85574314d3 (diff)
Add `--no-deps` to skip running recipe dependencies (#1819)
-rw-r--r--completions/just.bash2
-rw-r--r--completions/just.elvish1
-rw-r--r--completions/just.fish1
-rw-r--r--completions/just.powershell1
-rw-r--r--completions/just.zsh1
-rw-r--r--src/config.rs23
-rw-r--r--src/justfile.rs30
-rw-r--r--tests/lib.rs1
-rw-r--r--tests/no_dependencies.rs49
9 files changed, 94 insertions, 15 deletions
diff --git a/completions/just.bash b/completions/just.bash
index 4647ceb0..15adcf9b 100644
--- a/completions/just.bash
+++ b/completions/just.bash
@@ -20,7 +20,7 @@ _just() {
case "${cmd}" in
just)
- opts=" -n -q -u -v -e -l -h -V -f -d -c -s --check --yes --dry-run --highlight --no-dotenv --no-highlight --quiet --shell-command --clear-shell-args --unsorted --unstable --verbose --changelog --choose --dump --edit --evaluate --fmt --init --list --summary --variables --help --version --chooser --color --command-color --dump-format --list-heading --list-prefix --justfile --set --shell --shell-arg --working-directory --command --completions --show --dotenv-filename --dotenv-path <ARGUMENTS>... "
+ opts=" -n -q -u -v -e -l -h -V -f -d -c -s --check --yes --dry-run --highlight --no-deps --no-dotenv --no-highlight --quiet --shell-command --clear-shell-args --unsorted --unstable --verbose --changelog --choose --dump --edit --evaluate --fmt --init --list --summary --variables --help --version --chooser --color --command-color --dump-format --list-heading --list-prefix --justfile --set --shell --shell-arg --working-directory --command --completions --show --dotenv-filename --dotenv-path <ARGUMENTS>... "
if [[ ${cur} == -* ]] ; then
COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
return 0
diff --git a/completions/just.elvish b/completions/just.elvish
index 57ad502e..49b19a25 100644
--- a/completions/just.elvish
+++ b/completions/just.elvish
@@ -39,6 +39,7 @@ edit:completion:arg-completer[just] = [@words]{
cand -n 'Print what just would do without doing it'
cand --dry-run 'Print what just would do without doing it'
cand --highlight 'Highlight echoed recipe lines in bold'
+ cand --no-deps 'Don''t run recipe dependencies'
cand --no-dotenv 'Don''t load `.env` file'
cand --no-highlight 'Don''t highlight echoed recipe lines in bold'
cand -q 'Suppress all output'
diff --git a/completions/just.fish b/completions/just.fish
index aa28dbd9..1ec80576 100644
--- a/completions/just.fish
+++ b/completions/just.fish
@@ -55,6 +55,7 @@ complete -c just -n "__fish_use_subcommand" -l check -d 'Run `--fmt` in \'check\
complete -c just -n "__fish_use_subcommand" -l yes -d 'Automatically confirm all recipes.'
complete -c just -n "__fish_use_subcommand" -s n -l dry-run -d 'Print what just would do without doing it'
complete -c just -n "__fish_use_subcommand" -l highlight -d 'Highlight echoed recipe lines in bold'
+complete -c just -n "__fish_use_subcommand" -l no-deps -d 'Don\'t run recipe dependencies'
complete -c just -n "__fish_use_subcommand" -l no-dotenv -d 'Don\'t load `.env` file'
complete -c just -n "__fish_use_subcommand" -l no-highlight -d 'Don\'t highlight echoed recipe lines in bold'
complete -c just -n "__fish_use_subcommand" -s q -l quiet -d 'Suppress all output'
diff --git a/completions/just.powershell b/completions/just.powershell
index 92439dc2..cf3b6da5 100644
--- a/completions/just.powershell
+++ b/completions/just.powershell
@@ -44,6 +44,7 @@ Register-ArgumentCompleter -Native -CommandName 'just' -ScriptBlock {
[CompletionResult]::new('-n', 'n', [CompletionResultType]::ParameterName, 'Print what just would do without doing it')
[CompletionResult]::new('--dry-run', 'dry-run', [CompletionResultType]::ParameterName, 'Print what just would do without doing it')
[CompletionResult]::new('--highlight', 'highlight', [CompletionResultType]::ParameterName, 'Highlight echoed recipe lines in bold')
+ [CompletionResult]::new('--no-deps', 'no-deps', [CompletionResultType]::ParameterName, 'Don''t run recipe dependencies')
[CompletionResult]::new('--no-dotenv', 'no-dotenv', [CompletionResultType]::ParameterName, 'Don''t load `.env` file')
[CompletionResult]::new('--no-highlight', 'no-highlight', [CompletionResultType]::ParameterName, 'Don''t highlight echoed recipe lines in bold')
[CompletionResult]::new('-q', 'q', [CompletionResultType]::ParameterName, 'Suppress all output')
diff --git a/completions/just.zsh b/completions/just.zsh
index 46f35569..a8d1d7f1 100644
--- a/completions/just.zsh
+++ b/completions/just.zsh
@@ -40,6 +40,7 @@ _just() {
'(-q --quiet)-n[Print what just would do without doing it]' \
'(-q --quiet)--dry-run[Print what just would do without doing it]' \
'--highlight[Highlight echoed recipe lines in bold]' \
+'--no-deps[Don'\''t run recipe dependencies]' \
'--no-dotenv[Don'\''t load `.env` file]' \
'--no-highlight[Don'\''t highlight echoed recipe lines in bold]' \
'(-n --dry-run)-q[Suppress all output]' \
diff --git a/src/config.rs b/src/config.rs
index d5685856..0a071463 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -31,6 +31,7 @@ pub(crate) struct Config {
pub(crate) list_heading: String,
pub(crate) list_prefix: String,
pub(crate) load_dotenv: bool,
+ pub(crate) no_dependencies: bool,
pub(crate) search_config: SearchConfig,
pub(crate) shell: Option<String>,
pub(crate) shell_args: Option<Vec<String>>,
@@ -102,6 +103,7 @@ mod arg {
pub(crate) const JUSTFILE: &str = "JUSTFILE";
pub(crate) const LIST_HEADING: &str = "LIST-HEADING";
pub(crate) const LIST_PREFIX: &str = "LIST-PREFIX";
+ pub(crate) const NO_DEPS: &str = "NO-DEPS";
pub(crate) const NO_DOTENV: &str = "NO-DOTENV";
pub(crate) const NO_HIGHLIGHT: &str = "NO-HIGHLIGHT";
pub(crate) const QUIET: &str = "QUIET";
@@ -213,6 +215,12 @@ impl Config {
.value_name("TEXT")
.takes_value(true),
)
+ .arg (
+ Arg::with_name(arg::NO_DEPS)
+ .long("no-deps")
+ .alias("no-dependencies")
+ .help("Don't run recipe dependencies")
+ )
.arg(
Arg::with_name(arg::NO_DOTENV)
.long("no-dotenv")
@@ -650,6 +658,7 @@ impl Config {
.unwrap_or(" ")
.to_owned(),
load_dotenv: !matches.is_present(arg::NO_DOTENV),
+ no_dependencies: matches.is_present(arg::NO_DEPS),
search_config,
shell: matches.value_of(arg::SHELL).map(str::to_owned),
shell_args,
@@ -695,6 +704,7 @@ mod tests {
$(dry_run: $dry_run:expr,)?
$(dump_format: $dump_format:expr,)?
$(highlight: $highlight:expr,)?
+ $(no_dependencies: $no_dependencies:expr,)?
$(search_config: $search_config:expr,)?
$(shell: $shell:expr,)?
$(shell_args: $shell_args:expr,)?
@@ -714,6 +724,7 @@ mod tests {
$(dry_run: $dry_run,)?
$(dump_format: $dump_format,)?
$(highlight: $highlight,)?
+ $(no_dependencies: $no_dependencies,)?
$(search_config: $search_config,)?
$(shell: $shell,)?
$(shell_args: $shell_args,)?
@@ -890,6 +901,18 @@ mod tests {
}
test! {
+ name: no_deps,
+ args: ["--no-deps"],
+ no_dependencies: true,
+ }
+
+ test! {
+ name: no_dependencies,
+ args: ["--no-dependencies"],
+ no_dependencies: true,
+ }
+
+ test! {
name: unsorted_default,
args: [],
unsorted: false,
diff --git a/src/justfile.rs b/src/justfile.rs
index 0b862d29..84e1c2be 100644
--- a/src/justfile.rs
+++ b/src/justfile.rs
@@ -281,17 +281,17 @@ impl<'src> Justfile<'src> {
};
Self::run_recipe(
- &context,
- invocation.recipe,
&invocation
.arguments
.iter()
.copied()
.map(str::to_string)
.collect::<Vec<String>>(),
+ &context,
&dotenv,
- search,
&mut ran,
+ invocation.recipe,
+ search,
)?;
}
@@ -402,12 +402,12 @@ impl<'src> Justfile<'src> {
}
fn run_recipe(
- context: &RecipeContext<'src, '_>,
- recipe: &Recipe<'src>,
arguments: &[String],
+ context: &RecipeContext<'src, '_>,
dotenv: &BTreeMap<String, String>,
- search: &Search,
ran: &mut Ran<'src>,
+ recipe: &Recipe<'src>,
+ search: &Search,
) -> RunResult<'src> {
if ran.has_run(&recipe.namepath, arguments) {
return Ok(());
@@ -434,18 +434,20 @@ impl<'src> Justfile<'src> {
let mut evaluator =
Evaluator::recipe_evaluator(context.config, dotenv, &scope, context.settings, search);
- for Dependency { recipe, arguments } in recipe.dependencies.iter().take(recipe.priors) {
- let arguments = arguments
- .iter()
- .map(|argument| evaluator.evaluate_expression(argument))
- .collect::<RunResult<Vec<String>>>()?;
+ if !context.config.no_dependencies {
+ for Dependency { recipe, arguments } in recipe.dependencies.iter().take(recipe.priors) {
+ let arguments = arguments
+ .iter()
+ .map(|argument| evaluator.evaluate_expression(argument))
+ .collect::<RunResult<Vec<String>>>()?;
- Self::run_recipe(context, recipe, &arguments, dotenv, search, ran)?;
+ Self::run_recipe(&arguments, context, dotenv, ran, recipe, search)?;
+ }
}
recipe.run(context, dotenv, scope.child(), search, &positional)?;
- {
+ if !context.config.no_dependencies {
let mut ran = Ran::default();
for Dependency { recipe, arguments } in recipe.dependencies.iter().skip(recipe.priors) {
@@ -455,7 +457,7 @@ impl<'src> Justfile<'src> {
evaluated.push(evaluator.evaluate_expression(argument)?);
}
- Self::run_recipe(context, recipe, &evaluated, dotenv, search, &mut ran)?;
+ Self::run_recipe(&evaluated, context, dotenv, &mut ran, recipe, search)?;
}
}
diff --git a/tests/lib.rs b/tests/lib.rs
index 15799fb7..24d3ffa2 100644
--- a/tests/lib.rs
+++ b/tests/lib.rs
@@ -67,6 +67,7 @@ mod modules;
mod multibyte_char;
mod newline_escape;
mod no_cd;
+mod no_dependencies;
mod no_exit_message;
mod os_attributes;
mod parser;
diff --git a/tests/no_dependencies.rs b/tests/no_dependencies.rs
new file mode 100644
index 00000000..68a3ac10
--- /dev/null
+++ b/tests/no_dependencies.rs
@@ -0,0 +1,49 @@
+use super::*;
+
+#[test]
+fn skip_normal_dependency() {
+ Test::new()
+ .justfile(
+ "
+ a:
+ @echo 'a'
+ b: a
+ @echo 'b'
+ ",
+ )
+ .args(["--no-deps", "b"])
+ .stdout("b\n")
+ .run();
+}
+
+#[test]
+fn skip_prior_dependency() {
+ Test::new()
+ .justfile(
+ "
+ a:
+ @echo 'a'
+ b: && a
+ @echo 'b'
+ ",
+ )
+ .args(["--no-deps", "b"])
+ .stdout("b\n")
+ .run();
+}
+
+#[test]
+fn skip_dependency_multi() {
+ Test::new()
+ .justfile(
+ "
+ a:
+ @echo 'a'
+ b: && a
+ @echo 'b'
+ ",
+ )
+ .args(["--no-deps", "b", "a"])
+ .stdout("b\na\n")
+ .run();
+}