Skip to content

Commit

Permalink
Fix on ToString method (#25)
Browse files Browse the repository at this point in the history
* #19 (#19 (comment)): Fix on ToString method

* Version upgrade
  • Loading branch information
masesdevelopers authored Apr 6, 2022
1 parent b4d710a commit c714844
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 11 deletions.
21 changes: 12 additions & 9 deletions src/CLIParser/CLIParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,19 +76,22 @@ public static string ToString(this IEnumerable<IArgumentMetadata> metadatas, str
/// <returns>The string equivalent for command-line</returns>
public static string ToString(this IArgumentMetadata metadata, params object[] values)
{
if (metadata.Type != ArgumentType.Single && values == null || values.Length == 0) throw new ArgumentException("Cannot be null or empty", "values");
string valueStr = string.Empty;
if (metadata.IsMultiValue)
if (metadata.Type != ArgumentType.Single)
{
foreach (var item in values)
if (values == null || values.Length == 0) throw new ArgumentException("Cannot be null or empty", "values");
if (metadata.IsMultiValue)
{
valueStr += $"{item}{metadata.MultiValueSeparator}";
foreach (var item in values)
{
valueStr += $"{item}{metadata.MultiValueSeparator}";
}
valueStr = valueStr.Substring(0, valueStr.Length - 1);
}
else
{
valueStr = values[0].ToString();
}
valueStr = valueStr.Substring(0, valueStr.Length - 1);
}
else
{
valueStr = values[0].ToString();
}

var prefix = metadata.PrefixInUse;
Expand Down
2 changes: 1 addition & 1 deletion src/CLIParser/CLIParser.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<Owners>MASES s.r.l.</Owners>
<Authors>MASES s.r.l.</Authors>
<Company>MASES s.r.l.</Company>
<Version>3.1.1.0</Version>
<Version>3.1.2.0</Version>
<Product>CLIParser</Product>
<GenerateAssemblyInfo>true</GenerateAssemblyInfo>
<TargetFrameworks>netstandard2.0</TargetFrameworks>
Expand Down
2 changes: 1 addition & 1 deletion tests/CLIParserTest/CLIParserTest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<Copyright>Copyright © MASES s.r.l. 2022</Copyright>
<Authors>MASES s.r.l.</Authors>
<Company>MASES s.r.l.</Company>
<Version>3.1.1.0</Version>
<Version>3.1.2.0</Version>
<TargetFrameworks>net461;netcoreapp3.1;net5.0;net6.0</TargetFrameworks>
<OutputPath>..\..\bin\</OutputPath>
</PropertyGroup>
Expand Down
3 changes: 3 additions & 0 deletions tests/CLIParserTest/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,9 @@ static void Main(string[] args)

var result = parser.Parse(args);

var resultToString = parser.Arguments.ToString("MyParam2", "TEST");
resultToString = parser.Arguments.ToString("myval");

var fileInfo = parser.FromFile(result);

parser.Override(result, fileInfo);
Expand Down

0 comments on commit c714844

Please sign in to comment.