Skip to content

Commit baefb1f

Browse files
Clean up during PR review
1 parent 204a997 commit baefb1f

File tree

10 files changed

+195
-207
lines changed

10 files changed

+195
-207
lines changed

src/System.CommandLine.Tests/ParserTests.cs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -562,8 +562,7 @@ public void An_inner_command_with_the_same_name_does_not_capture()
562562
[Fact]
563563
public void When_nested_commands_all_accept_arguments_then_the_nearest_captures_the_arguments()
564564
{
565-
var command = new CliCommand(
566-
"outer")
565+
var command = new CliCommand("outer")
567566
{
568567
new CliArgument<string[]>("arg1"),
569568
new CliCommand("inner")
@@ -803,11 +802,12 @@ public void Subsequent_occurrences_of_tokens_matching_command_names_are_parsed_a
803802
}
804803
};
805804

806-
ParseResult result = CliParser.Parse(command, new[] { "the-command",
807-
"complete",
808-
"--position",
809-
"7",
810-
"the-command" });
805+
ParseResult result = CliParser.Parse(command, new[] {
806+
"the-command",
807+
"complete",
808+
"--position",
809+
"7",
810+
"the-command" });
811811

812812
CommandResult completeResult = result.CommandResult;
813813

@@ -975,7 +975,6 @@ public void Command_default_argument_value_does_not_override_parsed_value()
975975
}
976976
*/
977977

978-
979978
[Fact]
980979
public void Unmatched_tokens_that_look_like_options_are_not_split_into_smaller_tokens()
981980
{

src/System.CommandLine.Tests/TokenizerTests.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ public void The_tokenizer_can_handle_single_option()
2323
List<CliToken> tokens = null;
2424
List<string> errors = null;
2525
Tokenizer.Tokenize(args, command, new CliConfiguration(command), true, out tokens, out errors);
26-
Tokenizer.Tokenize(args, command, new CliConfiguration(command), true, out tokens, out errors);
2726

2827
tokens
2928
.Skip(1)

src/System.CommandLine/ParseResult.cs

Lines changed: 170 additions & 168 deletions
Large diffs are not rendered by default.

src/System.CommandLine/Parsing/ArgumentResult.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public ValueResult ValueResult
3434
var conversionValue = GetArgumentConversionResult().Value;
3535
var locations = Tokens.Select(token => token.Location).ToArray();
3636
//TODO: Remove this wrapper later
37-
_valueResult = new ValueResult(Argument, conversionValue, locations, ValueResultExtensions.GetValueResultOutcome(GetArgumentConversionResult()?.Result)); // null is temporary here
37+
_valueResult = new ValueResult(Argument, conversionValue, locations, ArgumentResult.GetValueResultOutcome(GetArgumentConversionResult()?.Result)); // null is temporary here
3838
}
3939
return _valueResult;
4040
}
@@ -47,7 +47,6 @@ public ValueResult ValueResult
4747

4848
internal bool ArgumentLimitReached => Argument.Arity.MaximumNumberOfValues == (_tokens?.Count ?? 0);
4949

50-
5150
internal ArgumentConversionResult GetArgumentConversionResult() =>
5251
_conversionResult ??= ValidateAndConvert(useValidators: true);
5352

@@ -236,5 +235,13 @@ ArgumentConversionResult ReportErrorIfNeeded(ArgumentConversionResult result)
236235
/// </summary>
237236
private SymbolResult AppliesToPublicSymbolResult =>
238237
Parent is OptionResult optionResult ? optionResult : this;
238+
239+
internal static ValueResultOutcome GetValueResultOutcome(ArgumentConversionResultType? resultType)
240+
=> resultType switch
241+
{
242+
ArgumentConversionResultType.NoArgument => ValueResultOutcome.NoArgument,
243+
ArgumentConversionResultType.Successful => ValueResultOutcome.Success,
244+
_ => ValueResultOutcome.HasErrors
245+
};
239246
}
240247
}

src/System.CommandLine/Parsing/CliToken.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,11 @@ internal sealed class CliToken : IEquatable<CliToken>
1515
public static CliToken CreateFromOtherToken(CliToken otherToken, string? arg, Location location)
1616
=> new(arg, otherToken.Type, otherToken.Symbol, location);
1717

18+
/*
1819
/// <param name="value">The string value of the token.</param>
1920
/// <param name="type">The type of the token.</param>
2021
/// <param name="symbol">The symbol represented by the token</param>
21-
/*
22+
2223
public CliToken(string? value, CliTokenType type, CliSymbol symbol)
2324
{
2425
Value = value ?? "";
@@ -28,6 +29,10 @@ public CliToken(string? value, CliTokenType type, CliSymbol symbol)
2829
}
2930
*/
3031

32+
/// <param name="value">The string value of the token.</param>
33+
/// <param name="type">The type of the token.</param>
34+
/// <param name="symbol">The symbol represented by the token</param>
35+
/// <param name="location">The location of the token in the args array or a response file</param>
3136
internal CliToken(string? value, CliTokenType type, CliSymbol? symbol, Location location)
3237
{
3338
Value = value ?? "";
Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,11 @@
11
// Copyright (c) .NET Foundation and contributors. All rights reserved.
22
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
33

4-
using System;
54
using System.Collections.Generic;
6-
using System.Linq;
7-
using System.Text;
8-
using System.Threading.Tasks;
95

106
namespace System.CommandLine.Parsing;
117

128
public class CommandValueResult
139
{
14-
IEnumerable<ValueResult> ValueResults { get; } = new List<ValueResult>();
15-
16-
10+
public IEnumerable<ValueResult> ValueResults { get; } = new List<ValueResult>();
1711
}

src/System.CommandLine/Parsing/OptionResult.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public ValueResult ValueResult
3737
var conversionValue = ArgumentConversionResult.Value;
3838
var locations = Tokens.Select(token => token.Location).ToArray();
3939
//TODO: Remove this wrapper later
40-
_valueResult = new ValueResult(Option, conversionValue, locations, ValueResultExtensions.GetValueResultOutcome(ArgumentConversionResult?.Result)); // null is temporary here
40+
_valueResult = new ValueResult(Option, conversionValue, locations, ArgumentResult.GetValueResultOutcome(ArgumentConversionResult?.Result)); // null is temporary here
4141
}
4242
return _valueResult;
4343
}

src/System.CommandLine/Parsing/SymbolResultTree.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ internal Dictionary<CliSymbol, ValueResult> GetValueResultDictionary()
7272
var dict = new Dictionary<CliSymbol, ValueResult>();
7373
foreach (KeyValuePair<CliSymbol, SymbolResult> pair in this)
7474
{
75-
var result = pair.Value;
75+
var result = pair.Value;
7676
if (result is OptionResult optionResult)
7777
{
7878
dict.Add(pair.Key, optionResult.ValueResult);

src/System.CommandLine/Parsing/ValueResultExtensions.cs

Lines changed: 0 additions & 17 deletions
This file was deleted.

src/System.CommandLine/System.CommandLine.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
<Compile Include="ArgumentArity.cs" />
2929
<Compile Include="Binding\ArgumentConversionResult.cs" />
3030
<Compile Include="Parsing\CommandValueResult.cs" />
31-
<Compile Include="Parsing\ValueResultExtensions.cs" />
3231
<Compile Include="Parsing\ValueResultOutcome.cs" />
3332
<Compile Include="Binding\ArgumentConversionResultType.cs" />
3433
<Compile Include="Binding\ArgumentConverter.cs" />

0 commit comments

Comments
 (0)