Repository: casey/just
Pull request #1961 (2024-03-12 16:44:42)

add --no-aliases flag to not show aliases when using --list
Hey there, this is my first contribution to this project, please let me know if any changes need to be made.

This PR aims to fix https://github.com/casey/just/issues/1891, since I came across the same problem.
I implemented the completions files, but I wasn't able to test most of them, I use zsh myself but the completions did not seem to work, although I could see them when passing `--completions=zsh`, perhaps you know what the problem is?


casey: Looks good to me! This just needs a test.
WJehee: Added a test, I'm not sure if the standard is to create a new file for this but that is what I did
casey: Looks like there's an issue with formatting.

Patch:
diff --git a/completions/just.bash b/completions/just.bash
index 1a47568b..57f00419 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  <ARGUMENTS>... "
+            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  <ARGUMENTS>... "
                 if [[ ${cur} == -* ]] ; then
                     COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
                     return 0
diff --git a/completions/just.elvish b/completions/just.elvish
index 804c520d..6ec3874e 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 d8ee779a..6664bd65 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 e7b207cf..fbdc529b 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 27e76c07..45f06a78 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 2022f278..21a6cf80 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<String>,
@@ -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 8dbcbaea..22102a50 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()]);
+        }
       }
     }
 


Test patch:
diff --git a/tests/lib.rs b/tests/lib.rs
index a9f3c344..b501b7e3 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 00000000..a5965d37
--- /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();
+}