-
-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Refactor `ALR_CONFIG` to `ALIRE_SETTINGS` * Replace --config with --settings * Code review * Post-merge fix
- Loading branch information
Showing
13 changed files
with
122 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,9 @@ with AAA.Strings; | |
|
||
with Ada.Directories; | ||
|
||
with Alire.Features; | ||
with Alire.Settings.Edit.Early_Load; | ||
with Alire.Version.Semver; | ||
|
||
with GNAT.Command_Line; | ||
with GNAT.OS_Lib; | ||
|
@@ -71,26 +73,26 @@ package body Alire_Early_Elaboration is | |
|
||
procedure Check_Switches is | ||
|
||
------------------------- | ||
-- Config_Switch_Error -- | ||
------------------------- | ||
--------------------------- | ||
-- Settings_Switch_Error -- | ||
--------------------------- | ||
|
||
procedure Config_Switch_Error (Switch : String) is | ||
procedure Settings_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; | ||
end Settings_Switch_Error; | ||
|
||
--------------------- | ||
-- Set_Config_Path -- | ||
--------------------- | ||
|
||
procedure Set_Config_Path (Path : String) is | ||
procedure Set_Config_Path (Switch, Path : String) is | ||
package Adirs renames Ada.Directories; | ||
begin | ||
if Path = "" then | ||
Config_Switch_Error ("--config"); | ||
Settings_Switch_Error (Switch); | ||
elsif not Adirs.Exists (Path) then | ||
Early_Error | ||
("Invalid non-existing configuration path: " & Path); | ||
|
@@ -102,6 +104,42 @@ package body Alire_Early_Elaboration is | |
end if; | ||
end Set_Config_Path; | ||
|
||
----------------------------- | ||
-- Check_Config_Deprecated -- | ||
----------------------------- | ||
|
||
use type Alire.Version.Semver.Version; | ||
Config_Deprecated : constant Boolean | ||
:= Alire.Version.Semver.Current >= Alire.Features.Config_Deprecated; | ||
|
||
procedure Check_Config_Deprecated is | ||
begin | ||
if Config_Deprecated then | ||
Early_Error | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
mosteo
Author
Member
|
||
("--config is deprecated, use --settings instead"); | ||
end if; | ||
end Check_Config_Deprecated; | ||
|
||
---------------- | ||
-- Check_Seen -- | ||
---------------- | ||
|
||
Settings_Seen : Boolean := False; | ||
|
||
procedure Check_Settings_Seen is | ||
begin | ||
if Settings_Seen then | ||
Early_Error | ||
("Only one of -s, --settings" | ||
& (if not Config_Deprecated | ||
then ", -c, --config" | ||
else "") | ||
& " allowed"); | ||
else | ||
Settings_Seen := True; | ||
end if; | ||
end Check_Settings_Seen; | ||
|
||
----------------------- | ||
-- Check_Long_Switch -- | ||
----------------------- | ||
|
@@ -116,26 +154,36 @@ package body Alire_Early_Elaboration is | |
Switch_D := True; | ||
Add_Scopes (Tail (Switch, "=")); | ||
elsif Has_Prefix (Switch, "--config") then | ||
Set_Config_Path (Tail (Switch, "=")); | ||
Check_Config_Deprecated; | ||
Check_Settings_Seen; | ||
Set_Config_Path (Switch, Tail (Switch, "=")); | ||
elsif Has_Prefix (Switch, "--settings") then | ||
Check_Settings_Seen; | ||
Set_Config_Path (Switch, Tail (Switch, "=")); | ||
end if; | ||
end Check_Long_Switch; | ||
|
||
Option : Character; | ||
|
||
begin | ||
loop | ||
-- We use the simpler Getopt form to avoid built-in help and other | ||
-- shenanigans. | ||
Option := Getopt ("* d? --debug? q v c= --config="); | ||
Option := Getopt ("* d? --debug? q v c= --config= s= --settings="); | ||
case Option is | ||
when ASCII.NUL => | ||
exit; | ||
when '*' => | ||
if not Subcommand_Seen then | ||
Check_Long_Switch (Full_Switch); | ||
end if; | ||
when 'c' => | ||
when 'c' | 's' => | ||
if not Subcommand_Seen then | ||
Set_Config_Path (Parameter); | ||
Check_Settings_Seen; | ||
if Option = 'c' then | ||
Check_Config_Deprecated; | ||
end if; | ||
Set_Config_Path ("-" & Option, Parameter); | ||
end if; | ||
when 'd' => | ||
if not Subcommand_Seen then | ||
|
@@ -164,8 +212,8 @@ package body Alire_Early_Elaboration is | |
end loop; | ||
exception | ||
when GNAT.Command_Line.Invalid_Parameter => | ||
if Option = 'c' then | ||
Config_Switch_Error ("-c"); | ||
if Option in 'c' | 's' then | ||
Settings_Switch_Error ("-" & Option); | ||
end if; | ||
when Exit_From_Command_Line => | ||
-- Something unexpected happened but it will be properly dealt | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,27 @@ | ||
""" | ||
Verify that errors are properly handled when no config path is given | ||
Verify that errors are properly handled when no settings path is given | ||
""" | ||
|
||
import os | ||
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) | ||
switch = "--settings" | ||
short = "-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) | ||
p = run_alr(switch, complain_on_error=False) | ||
assert_match(f"ERROR: Switch {switch} requires argument.*", p.out, flags=re.S) | ||
|
||
p = run_alr(short, complain_on_error=False) | ||
assert_match(f"ERROR: Switch {short} requires argument.*", p.out, flags=re.S) | ||
|
||
# Check also failure in case of duplication of switch | ||
path = os.getcwd() | ||
p = run_alr(f"{short}", path, f"{switch}={path}", "version", | ||
complain_on_error=False) | ||
assert_match(".*Only one of .* allowed", | ||
p.out) | ||
|
||
print('SUCCESS') |
Oops, something went wrong.
@mosteo Wasn't this supposed to be a warning instead of an error?