diff --git a/src/alire/alire_early_elaboration.adb b/src/alire/alire_early_elaboration.adb index da1231f6e..ae97124d0 100644 --- a/src/alire/alire_early_elaboration.adb +++ b/src/alire/alire_early_elaboration.adb @@ -71,6 +71,17 @@ package body Alire_Early_Elaboration is procedure Check_Switches is + ------------------------- + -- Config_Switch_Error -- + ------------------------- + + procedure Config_Switch_Error (Switch : String) is + begin + GNAT.IO.Put_Line + ("ERROR: Switch " & Switch & " requires argument (global)."); + Early_Error ("try ""alr --help"" for more information."); + end Config_Switch_Error; + --------------------- -- Set_Config_Path -- --------------------- @@ -78,7 +89,9 @@ package body Alire_Early_Elaboration is procedure Set_Config_Path (Path : String) is package Adirs renames Ada.Directories; begin - if not Adirs.Exists (Path) then + if Path = "" then + Config_Switch_Error ("--config"); + elsif not Adirs.Exists (Path) then Early_Error ("Invalid non-existing configuration path: " & Path); elsif Adirs.Kind (Path) not in Adirs.Directory then @@ -107,11 +120,13 @@ package body Alire_Early_Elaboration is end if; end Check_Long_Switch; + Option : Character; begin loop -- We use the simpler Getopt form to avoid built-in help and other -- shenanigans. - case Getopt ("* d? --debug? q v c= --config=") is + Option := Getopt ("* d? --debug? q v c= --config="); + case Option is when ASCII.NUL => exit; when '*' => @@ -148,6 +163,10 @@ package body Alire_Early_Elaboration is end case; end loop; exception + when GNAT.Command_Line.Invalid_Parameter => + if Option = 'c' then + Config_Switch_Error ("-c"); + end if; when Exit_From_Command_Line => -- Something unexpected happened but it will be properly dealt -- with later on, in the regular command-line parser. diff --git a/src/alr/alr-commands-install.adb b/src/alr/alr-commands-install.adb index 6b84f4693..974885a6e 100644 --- a/src/alr/alr-commands-install.adb +++ b/src/alr/alr-commands-install.adb @@ -122,8 +122,8 @@ package body Alr.Commands.Install is & "templates, should be able to coexist in a same installation prefix" & " without issue.") .New_Line - .Append ("You can use the --force to reinstall already installed " - & "releases.") + .Append ("You can use the --force global option to reinstall " + & "already installed releases.") ); -------------------- diff --git a/testsuite/tests/config/missing-config-path/test.py b/testsuite/tests/config/missing-config-path/test.py new file mode 100644 index 000000000..0047db813 --- /dev/null +++ b/testsuite/tests/config/missing-config-path/test.py @@ -0,0 +1,18 @@ +""" +Verify that errors are properly handled when no config path is given +""" + +from drivers.alr import run_alr +from drivers.asserts import assert_match + +import re + +p = run_alr("--config", complain_on_error=False) +assert p.status != 0, "command should fail" +assert_match("ERROR: Switch --config requires argument.*", p.out, flags=re.S) + +p = run_alr("-c", complain_on_error=False) +assert p.status != 0, "command should fail" +assert_match("ERROR: Switch -c requires argument.*", p.out, flags=re.S) + +print('SUCCESS') diff --git a/testsuite/tests/config/missing-config-path/test.yaml b/testsuite/tests/config/missing-config-path/test.yaml new file mode 100644 index 000000000..872fc1274 --- /dev/null +++ b/testsuite/tests/config/missing-config-path/test.yaml @@ -0,0 +1,3 @@ +driver: python-script +indexes: + basic_index: {}