From c763b00feb35179edea373f0dc3f99f3e7b2bf0b Mon Sep 17 00:00:00 2001 From: Alejandro R Mosteo Date: Mon, 1 Feb 2021 10:53:04 +0100 Subject: [PATCH] Rename `alr list` to `alr crates` (#671) * Rename `alr list` to `alr crates` This way there is less confusion about the purposes of `alr crates` and `alr search`; the former operates on crates and the latter on releases. * Fix bash completion * Document user-visible changes * Remove `crates` command, move to `search --crates` * Update bash completion for new situation * Update user-facing document * Updated testsuite --- doc/user-changes.md | 9 +++ scripts/alr-completion.bash | 9 ++- src/alire/alire-index-search.adb | 37 ++++++++++ src/alire/alire-index-search.ads | 9 +++ src/alr/alr-commands-list.adb | 70 ------------------- src/alr/alr-commands-list.ads | 20 ------ src/alr/alr-commands-search.adb | 51 +++++++++++++- src/alr/alr-commands-search.ads | 3 +- src/alr/alr-commands.adb | 2 - src/alr/alr-commands.ads | 1 - .../tests/index/bad-index-metadata/test.py | 2 +- .../tests/index/bad-index-version/test.py | 2 +- testsuite/tests/index/branch-mismatch/test.py | 2 +- testsuite/tests/index/check-enums/test.py | 2 +- .../tests/index/local-index-not-found/test.py | 2 +- .../tests/index/mismatched-crate/test.py | 2 +- .../tests/index/mismatched-parent/test.py | 2 +- .../index/origin-filesystem-bad-path/test.py | 2 +- .../tests/index/unexpected-contents/test.py | 2 +- testsuite/tests/publish/remote-origin/test.py | 2 +- 20 files changed, 122 insertions(+), 109 deletions(-) create mode 100644 src/alire/alire-index-search.adb create mode 100644 src/alire/alire-index-search.ads delete mode 100644 src/alr/alr-commands-list.adb delete mode 100644 src/alr/alr-commands-list.ads diff --git a/doc/user-changes.md b/doc/user-changes.md index c1e2ad5d..82162b90 100644 --- a/doc/user-changes.md +++ b/doc/user-changes.md @@ -4,6 +4,15 @@ This document is a development diary summarizing changes in `alr` that notably affect the user experience. It is intended as a one-stop point for users to stay on top of `alr` new features. +### The command `alr list` has been renamed to `alr search --crates` + +PR [#671](https://github.com/alire-project/alire/pull/671). + +To consolidate search functionality under the single `alr search` command, the +old behavior of `alr list` can now be achieved with `alr search --crates`. By +default, `alr search` looks into releases, but now it can look too into crates +with the new `--crates` switch. + ### Do not perform build relocations PR [#667](https://github.com/alire-project/alire/pull/667). diff --git a/scripts/alr-completion.bash b/scripts/alr-completion.bash index a85532b3..5bc9cb6b 100755 --- a/scripts/alr-completion.bash +++ b/scripts/alr-completion.bash @@ -11,6 +11,9 @@ _alr_commands=$(alr | sed -n '/Valid commands:/,/Help topics:/p' | tail -n +3 | # Long global switches _alr_global_switches=$(alr -h | grep -Eo -- '--[[:alnum:]-]+' | xargs) +# Crate names +_alr_crates=$(alr search --crates | cut -f1 -d' ') + # Command-aware long switches function _alr_completion() { curr=$2 @@ -43,9 +46,9 @@ function _alr_completion() { # Command-specific completions $found &&\ case $cmd in - get | list | show) + get | show) # Suggest crate names - COMPREPLY+=($(compgen -W "$(alr list | cut -f1 -d' ')" -- $curr)) + COMPREPLY+=($(compgen -W "$_alr_crates" -- $curr)) ;; index) @@ -63,7 +66,7 @@ function _alr_completion() { with) # When the previous word is "with", show any crate: - [ "$prev" == "with" ] && COMPREPLY+=($(compgen -W "$(alr list | cut -f1 -d' ')" -- $curr)) + [ "$prev" == "with" ] && COMPREPLY+=($(compgen -W "$_alr_crates" -- $curr)) # When the previous word is "--del", show direct dependencies: [ "$prev" == "--del" ] && COMPREPLY+=($(compgen -W "$(alr with | tail +2 | grep -Eo -- '[_a-z0-9]+')" -- $curr)) ;; diff --git a/src/alire/alire-index-search.adb b/src/alire/alire-index-search.adb new file mode 100644 index 00000000..4a012506 --- /dev/null +++ b/src/alire/alire-index-search.adb @@ -0,0 +1,37 @@ +with Alire.Utils.Tables; + +package body Alire.Index.Search is + + ------------------ + -- Print_Crates -- + ------------------ + + procedure Print_Crates (Substring : String := "") is + Table : Utils.Tables.Table; + Found : Natural := 0; + Lookup : constant String := Utils.To_Lower_Case (Substring); + + Busy : Simple_Logging.Ongoing := + Simple_Logging.Activity ("Searching"); + begin + for Crate of Alire.Index.All_Crates.all loop + if Lookup = "" or else + Utils.Contains (Utils.To_Lower_Case (+Crate.Name), Lookup) or else + Utils.Contains (Utils.To_Lower_Case (Crate.Description), Lookup) + then + Found := Found + 1; + Table.New_Row; + Table.Append (Crate.TTY_Name); + Table.Append (Crate.TTY_Description); + end if; + Busy.Step; + end loop; + + if Found = 0 then + Trace.Always ("No hits"); + else + Table.Print (Always, Separator => " "); + end if; + end Print_Crates; + +end Alire.Index.Search; diff --git a/src/alire/alire-index-search.ads b/src/alire/alire-index-search.ads new file mode 100644 index 00000000..ebeeb297 --- /dev/null +++ b/src/alire/alire-index-search.ads @@ -0,0 +1,9 @@ +package Alire.Index.Search is + + -- Functions for generating listings of crates/releases + + procedure Print_Crates (Substring : String := ""); + -- Print a list of crates containing Substring in their name/description, + -- or all of them when empty. + +end Alire.Index.Search; diff --git a/src/alr/alr-commands-list.adb b/src/alr/alr-commands-list.adb deleted file mode 100644 index 2fa700f5..00000000 --- a/src/alr/alr-commands-list.adb +++ /dev/null @@ -1,70 +0,0 @@ -with Alire.Index; -with Alire.Utils.Tables; - -with Alr.Utils; - -with Simple_Logging; - -package body Alr.Commands.List is - - ------------- - -- Execute -- - ------------- - - overriding procedure Execute (Cmd : in out Command) is - pragma Unreferenced (Cmd); - use Alr.Utils; - - Table : Alire.Utils.Tables.Table; - Search : constant String := - (if Num_Arguments = 1 - then Utils.To_Lower_Case (Argument (1)) - else ""); - Found : Natural := 0; - begin - if Num_Arguments > 1 then - Reportaise_Wrong_Arguments ("Too many search arguments"); - end if; - - Requires_Full_Index; - - declare - Busy : Simple_Logging.Ongoing := - Simple_Logging.Activity ("Searching"); - begin - for Crate of Alire.Index.All_Crates.all loop - if Num_Arguments = 0 or else - Contains (+Crate.Name, Search) or else - Contains (+Crate.Name, Search) - then - Found := Found + 1; - Table.New_Row; - Table.Append (Crate.TTY_Name); - Table.Append (Crate.TTY_Description); - end if; - Busy.Step; - end loop; - end; - - if Found = 0 then - Put_Line ("No hits"); - else - Table.Print (Always, Separator => " "); - end if; - end Execute; - - ---------------------- - -- Long_Description -- - ---------------------- - - overriding - function Long_Description (Cmd : Command) - return Alire.Utils.String_Vector is - (Alire.Utils.Empty_Vector - .Append ("Shows the list of all indexed crates without further" - & " details other than its common description. This command" - & " is intended as a fast alternative to the 'search' command" - & " when the information it provides is enough.") - ); - -end Alr.Commands.List; diff --git a/src/alr/alr-commands-list.ads b/src/alr/alr-commands-list.ads deleted file mode 100644 index e1c88c90..00000000 --- a/src/alr/alr-commands-list.ads +++ /dev/null @@ -1,20 +0,0 @@ -package Alr.Commands.List is - - type Command is new Commands.Command with null record; - - overriding - procedure Execute (Cmd : in out Command); - - overriding - function Long_Description (Cmd : Command) - return Alire.Utils.String_Vector; - - overriding - function Short_Description (Cmd : Command) return String - is ("See full list or a subset of indexed crates"); - - overriding - function Usage_Custom_Parameters (Cmd : Command) return String - is ("[]"); - -end Alr.Commands.List; diff --git a/src/alr/alr-commands-search.adb b/src/alr/alr-commands-search.adb index b5011348..5b918f2c 100644 --- a/src/alr/alr-commands-search.adb +++ b/src/alr/alr-commands-search.adb @@ -1,6 +1,6 @@ with Alire.Containers; with Alire.Externals; -with Alire.Index; +with Alire.Index.Search; with Alire.Crates; with Alire.Releases; with Alire.Solutions; @@ -91,6 +91,39 @@ package body Alr.Commands.Search is use Alire.Containers.Release_Sets; begin + + -- First, simpler case of search into crates + + if Cmd.Crates then + + -- Search into crates + + if Alire.Utils.Count_True + ((Cmd.Detect, Cmd.External, Cmd.Full, Cmd.Prop.all /= "")) > 0 + then + Reportaise_Wrong_Arguments + ("Extra switches are incompatible with --crates"); + end if; + + if Cmd.List and then Num_Arguments /= 0 then + Reportaise_Wrong_Arguments + ("Search substring and --list are incompatible"); + end if; + + Requires_Full_Index; + + Alire.Index.Search.Print_Crates + (Substring => (case Num_Arguments is + when 0 => "", + when 1 => Argument (1), + when others => + raise Wrong_Command_Arguments with + "Only one search substring supported")); + return; + end if; + + -- Remaining processing is for releases + if Cmd.Detect then Cmd.External := True; end if; @@ -186,11 +219,17 @@ package body Alr.Commands.Search is begin if Cmd.List then + + -- List releases + Trace.Detail ("Searching..."); for Crate of Alire.Index.All_Crates.all loop List_Crate (Crate); end loop; else + + -- Search into releases + declare Pattern : constant String := Argument (1); begin @@ -224,7 +263,9 @@ package body Alr.Commands.Search is & " with --property), and shows the most recent release" & " of matching crates (unless --full is specified).") .New_Line - .Append ("Besides version, description and release notes, a status" + .Append ("Use --crates to get a simple list of only crate names and " + & " descriptions. Otherwise," + & " besides version, description and release notes, a status" & " column with the following status flags is provided:") .New_Line .Append ("E: the release is externally provided.") @@ -252,6 +293,12 @@ package body Alr.Commands.Search is is use GNAT.Command_Line; begin + Define_Switch + (Config, + Cmd.Crates'Access, + "", "--crates", + "Restrict search and output to crate names and descriptions"); + Define_Switch (Config, Cmd.Detect'Access, diff --git a/src/alr/alr-commands-search.ads b/src/alr/alr-commands-search.ads index 0461e346..40f60c1d 100644 --- a/src/alr/alr-commands-search.ads +++ b/src/alr/alr-commands-search.ads @@ -17,7 +17,7 @@ package Alr.Commands.Search is overriding function Usage_Custom_Parameters (Cmd : Command) return String - is (" | --list"); + is (" | [--crates] [--full] --list"); overriding procedure Setup_Switches (Cmd : in out Command; @@ -26,6 +26,7 @@ package Alr.Commands.Search is private type Command is new Commands.Command with record + Crates : aliased Boolean := False; Detect : aliased Boolean := False; Full : aliased Boolean := False; List : aliased Boolean := False; diff --git a/src/alr/alr-commands.adb b/src/alr/alr-commands.adb index 48af2dee..33ac62b4 100644 --- a/src/alr/alr-commands.adb +++ b/src/alr/alr-commands.adb @@ -29,7 +29,6 @@ with Alr.Commands.Get; with Alr.Commands.Help; with Alr.Commands.Index; with Alr.Commands.Init; -with Alr.Commands.List; with Alr.Commands.Pin; with Alr.Commands.Printenv; with Alr.Commands.Publish; @@ -69,7 +68,6 @@ package body Alr.Commands is Cmd_Help => new Help.Command, Cmd_Index => new Index.Command, Cmd_Init => new Init.Command, - Cmd_List => new List.Command, Cmd_Pin => new Pin.Command, Cmd_Printenv => new Printenv.Command, Cmd_Publish => new Publish.Command, diff --git a/src/alr/alr-commands.ads b/src/alr/alr-commands.ads index 28c7e532..a63bd408 100644 --- a/src/alr/alr-commands.ads +++ b/src/alr/alr-commands.ads @@ -114,7 +114,6 @@ package Alr.Commands is Cmd_Help, Cmd_Index, Cmd_Init, - Cmd_List, Cmd_Pin, Cmd_Printenv, Cmd_Publish, diff --git a/testsuite/tests/index/bad-index-metadata/test.py b/testsuite/tests/index/bad-index-metadata/test.py index 33366926..05052046 100644 --- a/testsuite/tests/index/bad-index-metadata/test.py +++ b/testsuite/tests/index/bad-index-metadata/test.py @@ -6,7 +6,7 @@ from drivers.alr import run_alr from drivers.asserts import assert_match -p = run_alr('list', complain_on_error=False) +p = run_alr("search", "--crates", complain_on_error=False) assert_match( '.*index metadata contains unexpected fields.*', p.out) diff --git a/testsuite/tests/index/bad-index-version/test.py b/testsuite/tests/index/bad-index-version/test.py index c09578ae..ca43c07d 100644 --- a/testsuite/tests/index/bad-index-version/test.py +++ b/testsuite/tests/index/bad-index-version/test.py @@ -6,7 +6,7 @@ from drivers.alr import run_alr from drivers.asserts import assert_match -p = run_alr('list', complain_on_error=False) +p = run_alr("search", "--crates", complain_on_error=False) assert_match( '.*index version \(0\.0\.0\) is older than that expected by alr \(.*\).*', p.out) diff --git a/testsuite/tests/index/branch-mismatch/test.py b/testsuite/tests/index/branch-mismatch/test.py index 8bc1cb8c..7ed7a337 100644 --- a/testsuite/tests/index/branch-mismatch/test.py +++ b/testsuite/tests/index/branch-mismatch/test.py @@ -25,7 +25,7 @@ os.system('git ' + gitconfig + ' commit -q -m initialize') os.chdir(start) # Run the test. No alr version should use 'master' for the community index -p = run_alr('list', # Causes loading of the index +p = run_alr("search", "--crates", # Causes loading of the index complain_on_error=False) assert_match('.*Mismatched branch in checked out community index.*', diff --git a/testsuite/tests/index/check-enums/test.py b/testsuite/tests/index/check-enums/test.py index d06546b3..db4a1d61 100644 --- a/testsuite/tests/index/check-enums/test.py +++ b/testsuite/tests/index/check-enums/test.py @@ -9,7 +9,7 @@ import glob import os # Verify that we can list the index, despite containing an unknown distro value -run_alr("list") +run_alr("search", "--crates") # Verify that checking the index strictly does fail p = run_alr("index", "--check", complain_on_error=False) diff --git a/testsuite/tests/index/local-index-not-found/test.py b/testsuite/tests/index/local-index-not-found/test.py index 6f4596e5..bc571e7a 100644 --- a/testsuite/tests/index/local-index-not-found/test.py +++ b/testsuite/tests/index/local-index-not-found/test.py @@ -16,7 +16,7 @@ for d in ('no-such-directory', rm('alr-config', recursive=True) prepare_indexes('alr-config', '.', {'bad_index': {'dir': d, 'in_fixtures': False}}) - p = run_alr('list', complain_on_error=False, debug=False) + p = run_alr("search", "--crates", complain_on_error=False, debug=False) path_excerpt = os.path.join('alr-config', 'indexes', 'bad_index', 'index.toml') diff --git a/testsuite/tests/index/mismatched-crate/test.py b/testsuite/tests/index/mismatched-crate/test.py index ddae0720..95cf05da 100644 --- a/testsuite/tests/index/mismatched-crate/test.py +++ b/testsuite/tests/index/mismatched-crate/test.py @@ -7,7 +7,7 @@ import re from drivers.alr import run_alr from drivers.asserts import assert_match -p = run_alr("list", complain_on_error=False) +p = run_alr("search", "--crates", complain_on_error=False) assert_match('.*ERROR: Mismatch between manifest and shelf:.*', p.out, flags=re.S) diff --git a/testsuite/tests/index/mismatched-parent/test.py b/testsuite/tests/index/mismatched-parent/test.py index 99a5c97b..9de28d71 100644 --- a/testsuite/tests/index/mismatched-parent/test.py +++ b/testsuite/tests/index/mismatched-parent/test.py @@ -7,7 +7,7 @@ import re from drivers.alr import run_alr from drivers.asserts import assert_match -p = run_alr("list", complain_on_error=False) +p = run_alr("search", "--crates", complain_on_error=False) assert_match('.*ERROR: Mismatch between manifest and parent:.*', p.out, flags=re.S) diff --git a/testsuite/tests/index/origin-filesystem-bad-path/test.py b/testsuite/tests/index/origin-filesystem-bad-path/test.py index 2feda224..14466abe 100644 --- a/testsuite/tests/index/origin-filesystem-bad-path/test.py +++ b/testsuite/tests/index/origin-filesystem-bad-path/test.py @@ -13,7 +13,7 @@ def run(i, error): prepare_env(config_dir, os.environ) prepare_indexes( config_dir, '.', {'bad_index_{}'.format(i): {'in_fixtures': False}}) - p = run_alr('list', complain_on_error=False, debug=False) + p = run_alr("search", "--crates", complain_on_error=False, debug=False) assert_match( 'ERROR: {}\n' 'ERROR: alr encountered an unexpected error,' diff --git a/testsuite/tests/index/unexpected-contents/test.py b/testsuite/tests/index/unexpected-contents/test.py index c137d711..fdb16823 100644 --- a/testsuite/tests/index/unexpected-contents/test.py +++ b/testsuite/tests/index/unexpected-contents/test.py @@ -7,7 +7,7 @@ import re from drivers.alr import run_alr from drivers.asserts import assert_match -p = run_alr("list", complain_on_error=False) +p = run_alr("search", "--crates", complain_on_error=False) assert_match('.*ERROR: Unexpected file in index:.*shouldnt_be_here.+', p.out, flags=re.S) diff --git a/testsuite/tests/publish/remote-origin/test.py b/testsuite/tests/publish/remote-origin/test.py index afaf0ad2..8bd9c1b1 100644 --- a/testsuite/tests/publish/remote-origin/test.py +++ b/testsuite/tests/publish/remote-origin/test.py @@ -55,7 +55,7 @@ verify_manifest() copyfile(os.path.join("alire", "releases", "xxx-0.0.0.toml"), os.path.join("my_index", "xx", "xxx", "xxx-0.0.0.toml")) -p = run_alr("list") +p = run_alr("search", "--crates") assert "xxx" in p.out, "Crate not found in index contents" print('SUCCESS') -- 2.39.5