Skip to content

Commit

Permalink
Merge branch 'topic/vadim/cmdline' into 'master'
Browse files Browse the repository at this point in the history
Minor improvements of command line parser

See merge request eng/ide/VSS!312
  • Loading branch information
godunko committed Jan 25, 2024
2 parents edb63fc + 37eb89a commit fc24a67
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 17 deletions.
49 changes: 33 additions & 16 deletions source/os/implementation/vss-command_line-parsers.adb
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ package body VSS.Command_Line.Parsers is
end if;

elsif Option in Multivalue_Positional_Option'Class then
Self.Defined_Multivalue_Option.Replace_Element
Self.Defined_Multivalue_Positional_Option.Replace_Element
(Multivalue_Positional_Option (Option));

else
Expand Down Expand Up @@ -254,9 +254,10 @@ package body VSS.Command_Line.Parsers is
Usage.Append (Option.Name);
end loop;

if not Self.Defined_Multivalue_Option.Is_Empty then
if not Self.Defined_Multivalue_Positional_Option.Is_Empty then
Usage.Append (' ');
Usage.Append (Self.Defined_Multivalue_Option.Element.Name);
Usage.Append
(Self.Defined_Multivalue_Positional_Option.Element.Name);
Usage.Append ('');
end if;

Expand Down Expand Up @@ -289,14 +290,22 @@ package body VSS.Command_Line.Parsers is
Option_Text.Append (" <");
Option_Text.Append (Value_Option'Class (Option).Value_Name);
Option_Text.Append (">");

elsif Option in Name_Value_Option'Class then
Option_Text.Append (" <");
Option_Text.Append (Name_Value_Option'Class (Option).Name_Name);
Option_Text.Append ("=");
Option_Text.Append
(Name_Value_Option'Class (Option).Value_Name);
Option_Text.Append (">");
end if;

Append_Option_Description (Option_Text, Option.Description);
end loop;
end if;

if not Self.Defined_Positional_Options.Is_Empty
or else not Self.Defined_Multivalue_Option.Is_Empty
or else not Self.Defined_Multivalue_Positional_Option.Is_Empty
then
Result.Append (VSS.Strings.Empty_Virtual_String);
Result.Append ("Arguments:");
Expand All @@ -312,13 +321,15 @@ package body VSS.Command_Line.Parsers is
end loop;
end if;

if not Self.Defined_Multivalue_Option.Is_Empty then
if not Self.Defined_Multivalue_Positional_Option.Is_Empty then
Option_Text.Clear;
Option_Text.Append (" ");
Option_Text.Append (Self.Defined_Multivalue_Option.Element.Name);
Option_Text.Append
(Self.Defined_Multivalue_Positional_Option.Element.Name);

Append_Option_Description
(Option_Text, Self.Defined_Multivalue_Option.Element.Description);
(Option_Text,
Self.Defined_Multivalue_Positional_Option.Element.Description);
end if;

return Result;
Expand All @@ -339,8 +350,8 @@ package body VSS.Command_Line.Parsers is

elsif Option in Multivalue_Positional_Option'Class then
return
not Self.Defined_Multivalue_Option.Is_Empty
and then Self.Defined_Multivalue_Option.Element
not Self.Defined_Multivalue_Positional_Option.Is_Empty
and then Self.Defined_Multivalue_Positional_Option.Element
= Multivalue_Positional_Option (Option)
and then Natural (Self.Defined_Positional_Options.Length)
< Self.Positional_Options_Values.Length;
Expand Down Expand Up @@ -647,7 +658,7 @@ package body VSS.Command_Line.Parsers is

else
if Self.Defined_Positional_Options.Is_Empty then
if Self.Defined_Multivalue_Option.Is_Empty then
if Self.Defined_Multivalue_Positional_Option.Is_Empty then
Self.Error_Message := "unexpected positional argument";
Success := False;

Expand All @@ -658,7 +669,7 @@ package body VSS.Command_Line.Parsers is
if Self.Positional_Options_Values.Length
= Natural (Self.Defined_Positional_Options.Length)
then
if Self.Defined_Multivalue_Option.Is_Empty then
if Self.Defined_Multivalue_Positional_Option.Is_Empty then
Self.Error_Message := "unexpected positional argument";
Success := False;

Expand Down Expand Up @@ -830,12 +841,18 @@ package body VSS.Command_Line.Parsers is
Option : Multivalue_Positional_Option'Class)
return VSS.String_Vectors.Virtual_String_Vector is
begin
return
Self.Positional_Options_Values.Slice
(Natural (Self.Defined_Positional_Options.Length) + 1,
Self.Positional_Options_Values.Length);
if not Self.Defined_Multivalue_Positional_Option.Is_Empty
and then Self.Defined_Multivalue_Positional_Option.Element
= Multivalue_Positional_Option (Option)
then
return
Self.Positional_Options_Values.Slice
(Natural (Self.Defined_Positional_Options.Length) + 1,
Self.Positional_Options_Values.Length);

return VSS.String_Vectors.Empty_Virtual_String_Vector;
else
return VSS.String_Vectors.Empty_Virtual_String_Vector;
end if;
end Values;

end VSS.Command_Line.Parsers;
2 changes: 1 addition & 1 deletion source/os/vss-command_line-parsers.ads
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ private
Defined_Long_Options : Name_Sets.Set;
Defined_Named_Options : Named_Option_Maps.Map;
Defined_Positional_Options : Positional_Option_Vectors.Vector;
Defined_Multivalue_Option :
Defined_Multivalue_Positional_Option :
Multivalue_Positional_Option_Holders.Holder;

Error_Message : VSS.Strings.Virtual_String;
Expand Down

0 comments on commit fc24a67

Please sign in to comment.