Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 1cca1ac

Browse files
authored
Merge pull request #402 from zii-dmg/use-value-index
User [Value] index when parsing
2 parents e8cf96b + 719571c commit 1cca1ac

File tree

4 files changed

+36
-1
lines changed

4 files changed

+36
-1
lines changed

‎src/CommandLine/Core/InstanceBuilder.cs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public static ParserResult<T> Build<T>(
6767

6868
var valueSpecPropsResult =
6969
ValueMapper.MapValues(
70-
(from pt in specProps where pt.Specification.IsValue() select pt),
70+
(from pt in specProps where pt.Specification.IsValue() orderby ((ValueSpecification)pt.Specification).Indexselect pt),
7171
valuesPartition,
7272
(vals, type, isScalar) => TypeConverter.ChangeType(vals, type, isScalar, parsingCulture, ignoreValueCase));
7373

‎tests/CommandLine.Tests/CommandLine.Tests.csproj‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
<Compile Include="Fakes\Options_With_Default_Set_To_Sequence.cs" />
6262
<Compile Include="Fakes\Options_With_Guid.cs" />
6363
<Compile Include="Fakes\Options_With_SetName_That_Ends_With_Previous_SetName.cs" />
64+
<Compile Include="Fakes\Options_With_Shuffled_Index_Values.cs" />
6465
<Compile Include="Fakes\Options_With_Uri_And_SimpleType.cs" />
6566
<Compile Include="Fakes\Options_With_Switches.cs" />
6667
<Compile Include="Fakes\Options_With_Two_Option_Required_Set_To_True_And_Two_Sets.cs" />
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright 2005-2015 Giacomo Stelluti Scala & Contributors. All rights reserved. See License.md in the project root for license information.
2+
3+
using System;
4+
using System.Linq;
5+
6+
namespace CommandLine.Tests.Fakes
7+
{
8+
class Options_With_Shuffled_Index_Values
9+
{
10+
[Value(1)]
11+
public string Arg1 { get; set; }
12+
13+
[Value(2)]
14+
public string Arg2 { get; set; }
15+
16+
[Value(0)]
17+
public string Arg0 { get; set; }
18+
}
19+
}

‎tests/CommandLine.Tests/Unit/ParserTests.cs‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -803,5 +803,20 @@ public class NullDefaultCommandLineArguments
803803
[Option('u', "user", Default = null)]
804804
public string User { get; set; }
805805
}
806+
807+
[Fact]
808+
public void Parse_options_with_shuffled_index_values()
809+
{
810+
var parser = Parser.Default;
811+
parser.ParseArguments<Options_With_Shuffled_Index_Values>(
812+
new[] { "zero", "one", "two" })
813+
.WithNotParsed(errors => { throw new InvalidOperationException("Must be parsed."); })
814+
.WithParsed(args =>
815+
{
816+
Assert.Equal("zero", args.Arg0);
817+
Assert.Equal("one", args.Arg1);
818+
Assert.Equal("two", args.Arg2);
819+
});
820+
}
806821
}
807822
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /