From d3d0dbef7df9c9a2e6be1c57114e526ff0d42985 Mon Sep 17 00:00:00 2001 From: Wouter Jehee <38362353+WJehee@users.noreply.github.com> Date: Tue, 26 Mar 2024 20:20:46 +0100 Subject: [PATCH] Add --no-aliases to hide aliases in --list (#1961) --- completions/just.bash | 2 +- completions/just.elvish | 1 + completions/just.fish | 1 + completions/just.powershell | 1 + completions/just.zsh | 1 + src/config.rs | 8 ++++++++ src/subcommand.rs | 20 +++++++++++--------- tests/lib.rs | 1 + tests/no_aliases.rs | 20 ++++++++++++++++++++ 9 files changed, 45 insertions(+), 10 deletions(-) create mode 100644 tests/no_aliases.rs diff --git a/completions/just.bash b/completions/just.bash index 1a47568..57f0041 100644 --- a/completions/just.bash +++ b/completions/just.bash @@ -31,7 +31,7 @@ _just() { case "${cmd}" in just) - opts=" -n -q -u -v -e -l -h -V -f -d -c -s -E --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 ... " + opts=" -n -q -u -v -e -l -h -V -f -d -c -s -E --check --yes --dry-run --highlight --no-aliases --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 ... " if [[ ${cur} == -* ]] ; then COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) return 0 diff --git a/completions/just.elvish b/completions/just.elvish index 804c520..6ec3874 100644 --- a/completions/just.elvish +++ b/completions/just.elvish @@ -40,6 +40,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-aliases 'Don''t show aliases in list' 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' diff --git a/completions/just.fish b/completions/just.fish index d8ee779..6664bd6 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-aliases -d 'Don\'t show aliases in list' 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' diff --git a/completions/just.powershell b/completions/just.powershell index e7b207c..fbdc529 100644 --- a/completions/just.powershell +++ b/completions/just.powershell @@ -45,6 +45,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-aliases', 'no-aliases', [CompletionResultType]::ParameterName, 'Don''t show aliases in list') [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') diff --git a/completions/just.zsh b/completions/just.zsh index 27e76c0..45f06a7 100644 --- a/completions/just.zsh +++ b/completions/just.zsh @@ -41,6 +41,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-aliases[Don'\''t show aliases in list]' \ '--no-deps[Don'\''t run recipe dependencies]' \ '--no-dotenv[Don'\''t load `.env` file]' \ '--no-highlight[Don'\''t highlight echoed recipe lines in bold]' \ diff --git a/src/config.rs b/src/config.rs index 2022f27..21a6cf8 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_aliases: bool, pub(crate) no_dependencies: bool, pub(crate) search_config: SearchConfig, pub(crate) shell: Option, @@ -103,6 +104,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_ALIASES: &str = "NO-ALIASES"; pub(crate) const NO_DEPS: &str = "NO-DEPS"; pub(crate) const NO_DOTENV: &str = "NO-DOTENV"; pub(crate) const NO_HIGHLIGHT: &str = "NO-HIGHLIGHT"; @@ -215,6 +217,11 @@ impl Config { .value_name("TEXT") .takes_value(true), ) + .arg( + Arg::with_name(arg::NO_ALIASES) + .long("no-aliases") + .help("Don't show aliases in list") + ) .arg ( Arg::with_name(arg::NO_DEPS) .long("no-deps") @@ -659,6 +666,7 @@ impl Config { .unwrap_or(" ") .to_owned(), load_dotenv: !matches.is_present(arg::NO_DOTENV), + no_aliases: matches.is_present(arg::NO_ALIASES), no_dependencies: matches.is_present(arg::NO_DEPS), search_config, shell: matches.value_of(arg::SHELL).map(str::to_owned), diff --git a/src/subcommand.rs b/src/subcommand.rs index 8dbcbae..22102a5 100644 --- a/src/subcommand.rs +++ b/src/subcommand.rs @@ -429,16 +429,18 @@ impl Subcommand { fn list(config: &Config, level: usize, justfile: &Justfile) { // Construct a target to alias map. let mut recipe_aliases: BTreeMap<&str, Vec<&str>> = BTreeMap::new(); - for alias in justfile.aliases.values() { - if alias.is_private() { - continue; - } + if !config.no_aliases { + for alias in justfile.aliases.values() { + if alias.is_private() { + continue; + } - if recipe_aliases.contains_key(alias.target.name.lexeme()) { - let aliases = recipe_aliases.get_mut(alias.target.name.lexeme()).unwrap(); - aliases.push(alias.name.lexeme()); - } else { - recipe_aliases.insert(alias.target.name.lexeme(), vec![alias.name.lexeme()]); + if recipe_aliases.contains_key(alias.target.name.lexeme()) { + let aliases = recipe_aliases.get_mut(alias.target.name.lexeme()).unwrap(); + aliases.push(alias.name.lexeme()); + } else { + recipe_aliases.insert(alias.target.name.lexeme(), vec![alias.name.lexeme()]); + } } } diff --git a/tests/lib.rs b/tests/lib.rs index a9f3c34..b501b7e 100644 --- a/tests/lib.rs +++ b/tests/lib.rs @@ -67,6 +67,7 @@ mod misc; mod modules; mod multibyte_char; mod newline_escape; +mod no_aliases; mod no_cd; mod no_dependencies; mod no_exit_message; diff --git a/tests/no_aliases.rs b/tests/no_aliases.rs new file mode 100644 index 0000000..a5965d3 --- /dev/null +++ b/tests/no_aliases.rs @@ -0,0 +1,20 @@ +use super::*; + +#[test] +fn skip_alias() { + Test::new() + .justfile( + " + alias t := test1 + + test1: + @echo 'test1' + + test2: + @echo 'test2' + ", + ) + .args(["--no-aliases", "--list"]) + .stdout("Available recipes:\n test1\n test2\n") + .run(); +}