Skip to content

Commit c52e8fb

Browse files
committed
Revert "Merge branch 'robnasby-robnasby/double-dash-fix' of Properly assign arguments after a double dash to values (PR #610)"
This reverts commit c4eed10, reversing changes made to 959d3b2.
1 parent c4eed10 commit c52e8fb

File tree

5 files changed

+77
-64
lines changed

5 files changed

+77
-64
lines changed

Diff for: src/CommandLine/Core/Sequence.cs

+73-5
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ public static IEnumerable<Token> Partition(
3333
break;
3434

3535
case SequenceState.TokenFound:
36-
//IsValueForced are tokens after --
37-
if (token.IsValue() && !token.IsValueForced())
36+
if (token.IsValue())
3837
{
3938
if (sequences.TryGetValue(nameToken, out var sequence))
4039
{
@@ -67,16 +66,85 @@ public static IEnumerable<Token> Partition(
6766

6867
foreach (var kvp in sequences)
6968
{
70-
7169
yield return kvp.Key;
7270
foreach (var value in kvp.Value)
7371
{
7472
yield return value;
7573
}
76-
}
74+
}
75+
76+
//return from tseq in tokens.Pairwise(
77+
//(f, s) =>
78+
// f.IsName() && s.IsValue()
79+
// ? typeLookup(f.Text).MapValueOrDefault(info =>
80+
// info.TargetType == TargetType.Sequence
81+
// ? new[] { f }.Concat(tokens.OfSequence(f, info))
82+
// : new Token[] { }, new Token[] { })
83+
// : new Token[] { })
84+
// from t in tseq
85+
// select t;
7786
}
7887

79-
88+
//private static IEnumerable<Token> OfSequence(this IEnumerable<Token> tokens, Token nameToken, TypeDescriptor info)
89+
//{
90+
// var state = SequenceState.TokenSearch;
91+
// var count = 0;
92+
// var max = info.MaxItems.GetValueOrDefault(int.MaxValue);
93+
// var values = max != int.MaxValue
94+
// ? new List<Token>(max)
95+
// : new List<Token>();
96+
97+
// foreach (var token in tokens)
98+
// {
99+
// if (count == max)
100+
// {
101+
// break;
102+
// }
103+
104+
// switch (state)
105+
// {
106+
// case SequenceState.TokenSearch:
107+
// if (token.IsName() && token.Text.Equals(nameToken.Text))
108+
// {
109+
// state = SequenceState.TokenFound;
110+
// }
111+
// break;
112+
113+
// case SequenceState.TokenFound:
114+
// if (token.IsValue())
115+
// {
116+
// state = SequenceState.ValueFound;
117+
// count++;
118+
// values.Add(token);
119+
// }
120+
// else
121+
// {
122+
// // Invalid to provide option without value
123+
// return Enumerable.Empty<Token>();
124+
// }
125+
// break;
126+
127+
// case SequenceState.ValueFound:
128+
// if (token.IsValue())
129+
// {
130+
// count++;
131+
// values.Add(token);
132+
// }
133+
// else if (token.IsName() && token.Text.Equals(nameToken.Text))
134+
// {
135+
// state = SequenceState.TokenFound;
136+
// }
137+
// else
138+
// {
139+
// state = SequenceState.TokenSearch;
140+
// }
141+
// break;
142+
// }
143+
// }
144+
145+
// return values;
146+
//}
147+
80148
private enum SequenceState
81149
{
82150
TokenSearch,

Diff for: src/CommandLine/Core/Token.cs

+3-25
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,6 @@ public static Token Value(string text, bool explicitlyAssigned)
3232
return new Value(text, explicitlyAssigned);
3333
}
3434

35-
public static Token ValueForced(string text)
36-
{
37-
return new Value(text, false, true);
38-
}
39-
4035
public TokenType Tag
4136
{
4237
get { return tag; }
@@ -85,35 +80,23 @@ public bool Equals(Name other)
8580
class Value : Token, IEquatable<Value>
8681
{
8782
private readonly bool explicitlyAssigned;
88-
private readonly bool forced;
8983

9084
public Value(string text)
91-
: this(text, false, false)
85+
: this(text, false)
9286
{
9387
}
9488

9589
public Value(string text, bool explicitlyAssigned)
96-
: this(text, explicitlyAssigned, false)
97-
{
98-
}
99-
100-
public Value(string text, bool explicitlyAssigned, bool forced)
10190
: base(TokenType.Value, text)
10291
{
10392
this.explicitlyAssigned = explicitlyAssigned;
104-
this.forced = forced;
10593
}
10694

10795
public bool ExplicitlyAssigned
10896
{
10997
get { return explicitlyAssigned; }
11098
}
11199

112-
public bool Forced
113-
{
114-
get { return forced; }
115-
}
116-
117100
public override bool Equals(object obj)
118101
{
119102
var other = obj as Value;
@@ -137,7 +120,7 @@ public bool Equals(Value other)
137120
return false;
138121
}
139122

140-
return Tag.Equals(other.Tag) && Text.Equals(other.Text) && this.Forced == other.Forced;
123+
return Tag.Equals(other.Tag) && Text.Equals(other.Text);
141124
}
142125
}
143126

@@ -152,10 +135,5 @@ public static bool IsValue(this Token token)
152135
{
153136
return token.Tag == TokenType.Value;
154137
}
155-
156-
public static bool IsValueForced(this Token token)
157-
{
158-
return token.IsValue() && ((Value)token).Forced;
159-
}
160138
}
161-
}
139+
}

Diff for: src/CommandLine/Core/Tokenizer.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public static Result<IEnumerable<Token>, Error> PreprocessDashDash(
5050
if (arguments.Any(arg => arg.EqualsOrdinal("--")))
5151
{
5252
var tokenizerResult = tokenizer(arguments.TakeWhile(arg => !arg.EqualsOrdinal("--")));
53-
var values = arguments.SkipWhile(arg => !arg.EqualsOrdinal("--")).Skip(1).Select(Token.ValueForced);
53+
var values = arguments.SkipWhile(arg => !arg.EqualsOrdinal("--")).Skip(1).Select(Token.Value);
5454
return tokenizerResult.Map(tokens => tokens.Concat(values));
5555
}
5656
return tokenizer(arguments);

Diff for: tests/CommandLine.Tests/Fakes/Options_With_Option_Sequence_And_Value_Sequence.cs

-13
This file was deleted.

Diff for: tests/CommandLine.Tests/Unit/ParserTests.cs

-20
Original file line numberDiff line numberDiff line change
@@ -132,26 +132,6 @@ public void Parse_options_with_double_dash()
132132
// Teardown
133133
}
134134

135-
[Fact]
136-
public void Parse_options_with_double_dash_and_option_sequence()
137-
{
138-
var expectedOptions = new Options_With_Option_Sequence_And_Value_Sequence
139-
{
140-
OptionSequence = new[] { "option1", "option2", "option3" },
141-
ValueSequence = new[] { "value1", "value2", "value3" }
142-
};
143-
144-
var sut = new Parser(with => with.EnableDashDash = true);
145-
146-
// Exercize system
147-
var result =
148-
sut.ParseArguments<Options_With_Option_Sequence_And_Value_Sequence>(
149-
new[] { "--option-seq", "option1", "option2", "option3", "--", "value1", "value2", "value3" });
150-
151-
// Verify outcome
152-
((Parsed<Options_With_Option_Sequence_And_Value_Sequence>)result).Value.Should().BeEquivalentTo(expectedOptions);
153-
}
154-
155135
[Fact]
156136
public void Parse_options_with_double_dash_in_verbs_scenario()
157137
{

0 commit comments

Comments
 (0)