diff --git a/src/System.CommandLine.ApiCompatibility.Tests/ApiCompatibilityApprovalTests.System_CommandLine_api_is_not_changed.approved.txt b/src/System.CommandLine.ApiCompatibility.Tests/ApiCompatibilityApprovalTests.System_CommandLine_api_is_not_changed.approved.txt index 6b42819629..114cc0e3d3 100644 --- a/src/System.CommandLine.ApiCompatibility.Tests/ApiCompatibilityApprovalTests.System_CommandLine_api_is_not_changed.approved.txt +++ b/src/System.CommandLine.ApiCompatibility.Tests/ApiCompatibilityApprovalTests.System_CommandLine_api_is_not_changed.approved.txt @@ -79,7 +79,6 @@ System.CommandLine public static CommandLineBuilder AddMiddleware(this CommandLineBuilder builder, System.Action onInvoke, System.CommandLine.Invocation.MiddlewareOrder order = Default) public static CommandLineBuilder CancelOnProcessTermination(this CommandLineBuilder builder, System.Nullable timeout = null) public static CommandLineBuilder EnableDirectives(this CommandLineBuilder builder, System.Boolean value = True) - public static CommandLineBuilder EnableLegacyDoubleDashBehavior(this CommandLineBuilder builder, System.Boolean value = True) public static CommandLineBuilder EnablePosixBundling(this CommandLineBuilder builder, System.Boolean value = True) public static CommandLineBuilder RegisterWithDotnetSuggest(this CommandLineBuilder builder) public static CommandLineBuilder UseDefaults(this CommandLineBuilder builder) @@ -98,9 +97,8 @@ System.CommandLine public static CommandLineBuilder UseVersionOption(this CommandLineBuilder builder) public static CommandLineBuilder UseVersionOption(this CommandLineBuilder builder, System.String[] aliases) public class CommandLineConfiguration - .ctor(Command command, System.Boolean enablePosixBundling = True, System.Boolean enableDirectives = True, System.Boolean enableLegacyDoubleDashBehavior = False, System.Boolean enableTokenReplacement = True, LocalizationResources resources = null, System.Collections.Generic.IReadOnlyList middlewarePipeline = null, System.Func helpBuilderFactory = null, System.CommandLine.Parsing.TryReplaceToken tokenReplacer = null) + .ctor(Command command, System.Boolean enablePosixBundling = True, System.Boolean enableDirectives = True, System.Boolean enableTokenReplacement = True, LocalizationResources resources = null, System.Collections.Generic.IReadOnlyList middlewarePipeline = null, System.Func helpBuilderFactory = null, System.CommandLine.Parsing.TryReplaceToken tokenReplacer = null) public System.Boolean EnableDirectives { get; } - public System.Boolean EnableLegacyDoubleDashBehavior { get; } public System.Boolean EnablePosixBundling { get; } public System.Boolean EnableTokenReplacement { get; } public LocalizationResources LocalizationResources { get; } @@ -236,7 +234,6 @@ System.CommandLine public System.CommandLine.Parsing.CommandResult RootCommandResult { get; } public System.Collections.Generic.IReadOnlyList Tokens { get; } public System.Collections.Generic.IReadOnlyList UnmatchedTokens { get; } - public System.Collections.Generic.IReadOnlyList UnparsedTokens { get; } public System.CommandLine.Parsing.ArgumentResult FindResultFor(Argument argument) public System.CommandLine.Parsing.CommandResult FindResultFor(Command command) public System.CommandLine.Parsing.OptionResult FindResultFor(Option option) @@ -487,8 +484,7 @@ System.CommandLine.Parsing Command=1 Option=2 DoubleDash=3 - Unparsed=4 - Directive=5 + Directive=4 public delegate TryReplaceToken : System.MulticastDelegate, System.ICloneable, System.Runtime.Serialization.ISerializable .ctor(System.Object object, System.IntPtr method) public System.IAsyncResult BeginInvoke(System.String tokenToReplace, ref System.Collections.Generic.IReadOnlyList replacementTokens, ref System.String& errorMessage, System.AsyncCallback callback, System.Object object) diff --git a/src/System.CommandLine.Hosting.Tests/HostingTests.cs b/src/System.CommandLine.Hosting.Tests/HostingTests.cs index 4f89e8ceef..12e06c8007 100644 --- a/src/System.CommandLine.Hosting.Tests/HostingTests.cs +++ b/src/System.CommandLine.Hosting.Tests/HostingTests.cs @@ -91,11 +91,11 @@ void Execute(IHost host) } [Fact] - public static void UseHost_UnparsedTokens_can_propagate_to_Host_Configuration() + public static void UseHost_UnmatchedTokens_can_propagate_to_Host_Configuration() { const string testArgument = "test"; - const string testKey = "unparsed-config"; - string commandLineArgs = $"-- --{testKey} {testArgument}"; + const string testKey = "unmatched-config"; + string commandLineArgs = $"--{testKey} {testArgument}"; string testConfigValue = null; @@ -110,11 +110,10 @@ void Execute(IHost host) { Handler = CommandHandler.Create(Execute), }) - .EnableLegacyDoubleDashBehavior() .UseHost(host => { var invocation = (InvocationContext)host.Properties[typeof(InvocationContext)]; - var args = invocation.ParseResult.UnparsedTokens.ToArray(); + var args = invocation.ParseResult.UnmatchedTokens.ToArray(); host.ConfigureHostConfiguration(config => { config.AddCommandLine(args); @@ -129,11 +128,11 @@ void Execute(IHost host) } [Fact] - public static void UseHost_UnparsedTokens_are_available_in_HostBuilder_factory() + public static void UseHost_UnmatchedTokens_are_available_in_HostBuilder_factory() { const string testArgument = "test"; - const string testKey = "unparsed-config"; - string commandLineArgs = $"-- --{testKey} {testArgument}"; + const string testKey = "unmatched-config"; + string commandLineArgs = $"--{testKey} {testArgument}"; string testConfigValue = null; @@ -148,7 +147,6 @@ void Execute(IHost host) { Handler = CommandHandler.Create(Execute), }) - .EnableLegacyDoubleDashBehavior() .UseHost(args => { var host = new HostBuilder(); diff --git a/src/System.CommandLine.Hosting/HostingExtensions.cs b/src/System.CommandLine.Hosting/HostingExtensions.cs index e0b0cfe1da..70c7969f57 100644 --- a/src/System.CommandLine.Hosting/HostingExtensions.cs +++ b/src/System.CommandLine.Hosting/HostingExtensions.cs @@ -20,7 +20,7 @@ public static CommandLineBuilder UseHost(this CommandLineBuilder builder, Action configureHost = null) => builder.AddMiddleware(async (invocation, next) => { - var argsRemaining = invocation.ParseResult.UnparsedTokens.ToArray(); + var argsRemaining = invocation.ParseResult.UnmatchedTokens.ToArray(); var hostBuilder = hostBuilderFactory?.Invoke(argsRemaining) ?? new HostBuilder(); hostBuilder.Properties[typeof(InvocationContext)] = invocation; diff --git a/src/System.CommandLine.Suggest/SuggestionDispatcher.cs b/src/System.CommandLine.Suggest/SuggestionDispatcher.cs index 3897cfc93b..516142af96 100644 --- a/src/System.CommandLine.Suggest/SuggestionDispatcher.cs +++ b/src/System.CommandLine.Suggest/SuggestionDispatcher.cs @@ -74,9 +74,8 @@ public SuggestionDispatcher(ISuggestionRegistration suggestionRegistration, ISug RegisterCommand, CompleteScriptCommand }; - + root.TreatUnmatchedTokensAsErrors = false; Parser = new CommandLineBuilder(root) - .EnableLegacyDoubleDashBehavior() .UseVersionOption() .UseHelp() .UseParseDirective() @@ -207,7 +206,7 @@ public static string FormatSuggestionArguments( int position, string targetExeName) { - var tokens = parseResult.UnparsedTokens; + var tokens = parseResult.UnmatchedTokens; var commandLine = tokens.FirstOrDefault() ?? ""; diff --git a/src/System.CommandLine.Tests/ArgumentTests.cs b/src/System.CommandLine.Tests/ArgumentTests.cs index 6509d6dd80..51351ef5e1 100644 --- a/src/System.CommandLine.Tests/ArgumentTests.cs +++ b/src/System.CommandLine.Tests/ArgumentTests.cs @@ -559,7 +559,7 @@ public void Custom_parser_can_pass_on_remaining_tokens(string commandLine) } [Fact] - public void When_tokens_are_passed_on_by_custom_parser_on_last_argument_then_they_become_unparsed_tokens() + public void When_tokens_are_passed_on_by_custom_parser_on_last_argument_then_they_become_unmatched_tokens() { var argument1 = new Argument( @@ -583,7 +583,7 @@ public void When_tokens_are_passed_on_by_custom_parser_on_last_argument_then_the var parseResult = command.Parse("1 2 3 4 5 6 7 8"); - parseResult.UnparsedTokens + parseResult.UnmatchedTokens .Should() .BeEquivalentTo(new[] { "4", "5", "6", "7", "8" }, options => options.WithStrictOrdering()); diff --git a/src/System.CommandLine.Tests/ParserTests.DoubleDash.cs b/src/System.CommandLine.Tests/ParserTests.DoubleDash.cs index 6da82d17ce..d52bfef122 100644 --- a/src/System.CommandLine.Tests/ParserTests.DoubleDash.cs +++ b/src/System.CommandLine.Tests/ParserTests.DoubleDash.cs @@ -24,7 +24,6 @@ public void Subsequent_tokens_are_parsed_as_arguments_even_if_they_match_option_ }; var result = new CommandLineBuilder(rootCommand) - .EnableLegacyDoubleDashBehavior(false) .Build() .Parse("-o \"some stuff\" -- -o --one -x -y -z -o:foo"); @@ -34,11 +33,11 @@ public void Subsequent_tokens_are_parsed_as_arguments_even_if_they_match_option_ result.GetValueForArgument(argument).Should().BeEquivalentSequenceTo("-o", "--one", "-x", "-y", "-z", "-o:foo"); - result.UnparsedTokens.Should().BeEmpty(); + result.UnmatchedTokens.Should().BeEmpty(); } [Fact] - public void Unparsed_tokens_is_empty() + public void Unmatched_tokens_is_empty() { var option = new Option(new[] { "-o", "--one" }); var argument = new Argument(); @@ -49,11 +48,10 @@ public void Unparsed_tokens_is_empty() }; var result = new CommandLineBuilder(rootCommand) - .EnableLegacyDoubleDashBehavior(false) .Build() .Parse("-o \"some stuff\" -- --one -x -y -z -o:foo"); - result.UnparsedTokens.Should().BeEmpty(); + result.UnmatchedTokens.Should().BeEmpty(); } [Fact] // https://github.com/dotnet/command-line-api/issues/1631 @@ -68,7 +66,6 @@ public void No_errors_are_generated() }; var result = new CommandLineBuilder(rootCommand) - .EnableLegacyDoubleDashBehavior(false) .Build() .Parse("-o \"some stuff\" -- -o --one -x -y -z -o:foo"); @@ -85,7 +82,6 @@ public void A_second_double_dash_is_parsed_as_an_argument() }; var result = new CommandLineBuilder(rootCommand) - .EnableLegacyDoubleDashBehavior(false) .Build() .Parse("a b c -- -- d"); @@ -94,69 +90,5 @@ public void A_second_double_dash_is_parsed_as_an_argument() strings.Should().BeEquivalentSequenceTo("a", "b", "c", "--", "d"); } } - - public class LegacyDoubleDashBehavior - { - [Fact] - public void The_portion_of_the_command_line_following_a_double_is_treated_as_unparsed_tokens() - { - var result = new CommandLineBuilder(new RootCommand { new Option("-o") }) - .EnableLegacyDoubleDashBehavior() - .Build() - .Parse("-o \"some stuff\" -- x y z"); - - result.UnparsedTokens - .Should() - .BeEquivalentSequenceTo("x", "y", "z"); - } - - [Fact] - public void Subsequent_tokens_matching_options_will_be_treated_as_unparsed_tokens() - { - var optionO = new Option(new[] { "-o" }); - var optionX = new Option(new[] { "-x" }); - var optionY = new Option(new[] { "-y" }); - var optionZ = new Option(new[] { "-z" }); - var rootCommand = new RootCommand - { - optionO, - optionX, - optionY, - optionZ - }; - var result = new CommandLineBuilder(rootCommand) - .EnableLegacyDoubleDashBehavior() - .Build() - .Parse("-o \"some stuff\" -- -x -y -z -o:foo"); - - result.HasOption(optionO).Should().BeTrue(); - result.HasOption(optionX).Should().BeFalse(); - result.HasOption(optionY).Should().BeFalse(); - result.HasOption(optionZ).Should().BeFalse(); - - result.UnparsedTokens - .Should() - .BeEquivalentSequenceTo("-x", - "-y", - "-z", - "-o:foo"); - } - - [Fact] - public void Subsequent_tokens_matching_argument_will_be_treated_as_unparsed_tokens() - { - var argument = new Argument(); - var rootCommand = new RootCommand - { - argument - }; - var result = new CommandLineBuilder(rootCommand) - .EnableLegacyDoubleDashBehavior() - .Build() - .Parse("1 2 3 -- 4 5 6 7"); - - result.GetValueForArgument(argument).Should().BeEquivalentSequenceTo(1, 2, 3); - } - } } } \ No newline at end of file diff --git a/src/System.CommandLine.Tests/ParserTests.MultipleArguments.cs b/src/System.CommandLine.Tests/ParserTests.MultipleArguments.cs index c84ab54eac..261e2d1d26 100644 --- a/src/System.CommandLine.Tests/ParserTests.MultipleArguments.cs +++ b/src/System.CommandLine.Tests/ParserTests.MultipleArguments.cs @@ -216,7 +216,7 @@ public void Tokens_that_cannot_be_converted_by_multiple_arity_argument_flow_to_n .Should() .Be("four"); - result.UnparsedTokens + result.UnmatchedTokens .Should() .ContainSingle() .Which diff --git a/src/System.CommandLine/Builder/CommandLineBuilder.cs b/src/System.CommandLine/Builder/CommandLineBuilder.cs index 96f079f8c2..547419f88d 100644 --- a/src/System.CommandLine/Builder/CommandLineBuilder.cs +++ b/src/System.CommandLine/Builder/CommandLineBuilder.cs @@ -45,12 +45,6 @@ public CommandLineBuilder(Command? rootCommand = null) internal bool EnablePosixBundling { get; set; } = true; internal bool EnableTokenReplacement { get; set; } = true; - - /// - /// Determines the behavior when parsing a double dash (--) in a command line. - /// - /// When set to , all tokens following -- will be placed into the collection. When set to , all tokens following -- will be treated as command arguments, even if they match an existing option. - internal bool EnableLegacyDoubleDashBehavior { get; set; } internal void CustomizeHelpLayout(Action customize) => _customizeHelpBuilder = customize; @@ -97,7 +91,6 @@ public Parser Build() => Command, enablePosixBundling: EnablePosixBundling, enableDirectives: EnableDirectives, - enableLegacyDoubleDashBehavior: EnableLegacyDoubleDashBehavior, enableTokenReplacement: EnableTokenReplacement, resources: LocalizationResources, middlewarePipeline: _middlewareList is null diff --git a/src/System.CommandLine/Builder/CommandLineBuilderExtensions.cs b/src/System.CommandLine/Builder/CommandLineBuilderExtensions.cs index c20f08c841..67b65dc96d 100644 --- a/src/System.CommandLine/Builder/CommandLineBuilderExtensions.cs +++ b/src/System.CommandLine/Builder/CommandLineBuilderExtensions.cs @@ -164,19 +164,6 @@ public static CommandLineBuilder EnableDirectives( return builder; } - /// - /// Determines the behavior when parsing a double dash (--) in a command line. - /// - /// A command line builder. - /// to place all tokens following -- into the collection. to treat all tokens following -- as command arguments, even if they match an existing option. - public static CommandLineBuilder EnableLegacyDoubleDashBehavior( - this CommandLineBuilder builder, - bool value = true) - { - builder.EnableLegacyDoubleDashBehavior = value; - return builder; - } - /// /// Enables the parser to recognize and expand POSIX-style bundled options. /// diff --git a/src/System.CommandLine/CommandLineConfiguration.cs b/src/System.CommandLine/CommandLineConfiguration.cs index 85e9eeb6f3..4da27d7dad 100644 --- a/src/System.CommandLine/CommandLineConfiguration.cs +++ b/src/System.CommandLine/CommandLineConfiguration.cs @@ -25,7 +25,6 @@ public class CommandLineConfiguration /// The root command for the parser. /// to enable POSIX bundling; otherwise, . /// to enable directive parsing; otherwise, . - /// Enables the legacy behavior of the -- token, which is to ignore parsing of subsequent tokens and place them in the list. /// to enable token replacement; otherwise, . /// Provide custom validation messages. /// Provide a custom middleware pipeline. @@ -35,7 +34,6 @@ public CommandLineConfiguration( Command command, bool enablePosixBundling = true, bool enableDirectives = true, - bool enableLegacyDoubleDashBehavior = false, bool enableTokenReplacement = true, LocalizationResources? resources = null, IReadOnlyList? middlewarePipeline = null, @@ -43,8 +41,6 @@ public CommandLineConfiguration( TryReplaceToken? tokenReplacer = null) { RootCommand = command ?? throw new ArgumentNullException(nameof(command)); - - EnableLegacyDoubleDashBehavior = enableLegacyDoubleDashBehavior; EnableTokenReplacement = enableTokenReplacement; EnablePosixBundling = enablePosixBundling; EnableDirectives = enableDirectives; @@ -72,11 +68,6 @@ internal static HelpBuilder DefaultHelpBuilderFactory(BindingContext context, in /// public bool EnableDirectives { get; } - /// - /// Enables the legacy behavior of the -- token, which is to ignore parsing of subsequent tokens and place them in the list. - /// - public bool EnableLegacyDoubleDashBehavior { get; } - /// /// Gets a value indicating whether POSIX bundling is enabled. /// diff --git a/src/System.CommandLine/ParseResult.cs b/src/System.CommandLine/ParseResult.cs index aafe6c1ccc..b84acded9f 100644 --- a/src/System.CommandLine/ParseResult.cs +++ b/src/System.CommandLine/ParseResult.cs @@ -16,7 +16,6 @@ public class ParseResult { private readonly List _errors; private readonly RootCommandResult _rootCommandResult; - private readonly IReadOnlyList _unparsedTokens; private readonly IReadOnlyList _unmatchedTokens; private CompletionContext? _completionContext; @@ -26,7 +25,6 @@ internal ParseResult( CommandResult commandResult, DirectiveCollection directives, TokenizeResult tokenizeResult, - IReadOnlyList? unparsedTokens, IReadOnlyList? unmatchedTokens, List? errors, string? commandLineText = null) @@ -53,7 +51,6 @@ internal ParseResult( Tokens = Array.Empty(); } - _unparsedTokens = unparsedTokens ?? Array.Empty(); _errors = errors ?? new List(); CommandLineText = commandLineText; @@ -120,12 +117,6 @@ internal ParseResult( /// public IReadOnlyList UnmatchedTokens => _unmatchedTokens.Select(t => t.Value).ToArray(); - /// - /// Gets the list of tokens used on the command line that were ignored by the parser. - /// - /// This list will contain all of the tokens following the first occurrence of a -- token if is set to . - public IReadOnlyList UnparsedTokens => _unparsedTokens.Select(t => t.Value).ToArray(); - /// /// Gets the completion context for the parse result. /// diff --git a/src/System.CommandLine/Parsing/ParseOperation.cs b/src/System.CommandLine/Parsing/ParseOperation.cs index 79e7a5bdc4..1b6849c40e 100644 --- a/src/System.CommandLine/Parsing/ParseOperation.cs +++ b/src/System.CommandLine/Parsing/ParseOperation.cs @@ -27,8 +27,6 @@ public ParseOperation( public List? UnmatchedTokens { get; private set; } - public List? UnparsedTokens { get; private set; } - private void Advance() => _index++; private bool More(out TokenType currentTokenType) @@ -56,8 +54,6 @@ private CommandNode ParseRootCommand() ParseCommandChildren(rootCommandNode); - ParseRemainingTokens(); - return rootCommandNode; } @@ -79,12 +75,6 @@ private void ParseCommandChildren(CommandNode parent) while (More(out TokenType currentTokenType)) { - if (_configuration.EnableLegacyDoubleDashBehavior && - currentTokenType == TokenType.DoubleDash) - { - return; - } - if (currentTokenType == TokenType.Command) { ParseSubcommand(parent); @@ -231,25 +221,6 @@ void ParseDirective(CommandNode parent) } } - private void ParseRemainingTokens() - { - var foundEndOfArguments = false; - - while (More(out TokenType currentTokenType)) - { - if (currentTokenType == TokenType.DoubleDash) - { - foundEndOfArguments = true; - } - else if (foundEndOfArguments) - { - AddCurrentTokenToUnparsed(); - } - - Advance(); - } - } - private void AddCurrentTokenToUnmatched() { if (CurrentToken.Type == TokenType.DoubleDash) @@ -259,7 +230,5 @@ private void AddCurrentTokenToUnmatched() (UnmatchedTokens ??= new()).Add(CurrentToken); } - - private void AddCurrentTokenToUnparsed() => (UnparsedTokens ??= new()).Add(CurrentToken); } } \ No newline at end of file diff --git a/src/System.CommandLine/Parsing/ParseResultVisitor.cs b/src/System.CommandLine/Parsing/ParseResultVisitor.cs index d57b076dc6..ce4502f740 100644 --- a/src/System.CommandLine/Parsing/ParseResultVisitor.cs +++ b/src/System.CommandLine/Parsing/ParseResultVisitor.cs @@ -15,8 +15,7 @@ internal sealed class ParseResultVisitor private readonly string? _rawInput; private readonly DirectiveCollection _directives = new(); - private List? _unparsedTokens; - private readonly List? _unmatchedTokens; + private List? _unmatchedTokens; private readonly List _errors; private readonly Dictionary _symbolResults = new(); @@ -31,13 +30,11 @@ internal sealed class ParseResultVisitor public ParseResultVisitor( Parser parser, TokenizeResult tokenizeResult, - List? unparsedTokens, List? unmatchedTokens, string? rawInput) { _parser = parser; _tokenizeResult = tokenizeResult; - _unparsedTokens = unparsedTokens; _unmatchedTokens = unmatchedTokens; _rawInput = rawInput; _errors = new List(_tokenizeResult.Errors.Count); @@ -301,8 +298,8 @@ private void ValidateAndConvertArgumentResults(IReadOnlyList arguments if (argumentResult.PassedOnTokens is { } && i == arguments.Count - 1) { - _unparsedTokens ??= new List(); - _unparsedTokens.AddRange(argumentResult.PassedOnTokens); + _unmatchedTokens ??= new List(); + _unmatchedTokens.AddRange(argumentResult.PassedOnTokens); } } } @@ -620,7 +617,6 @@ public ParseResult GetResult() => _innermostCommandResult ?? throw new InvalidOperationException("No command was found"), _directives, _tokenizeResult, - _unparsedTokens, _unmatchedTokens, _errors, _rawInput); diff --git a/src/System.CommandLine/Parsing/Parser.cs b/src/System.CommandLine/Parsing/Parser.cs index db649b2c78..3271e062fb 100644 --- a/src/System.CommandLine/Parsing/Parser.cs +++ b/src/System.CommandLine/Parsing/Parser.cs @@ -57,7 +57,6 @@ public ParseResult Parse( var visitor = new ParseResultVisitor( this, tokenizeResult, - operation.UnparsedTokens, operation.UnmatchedTokens, rawInput); diff --git a/src/System.CommandLine/Parsing/StringExtensions.cs b/src/System.CommandLine/Parsing/StringExtensions.cs index 9033b23305..5de4fbcbe3 100644 --- a/src/System.CommandLine/Parsing/StringExtensions.cs +++ b/src/System.CommandLine/Parsing/StringExtensions.cs @@ -27,8 +27,8 @@ internal static int IndexOfCaseInsensitive( internal static string RemovePrefix(this string alias) { int prefixLength = GetPrefixLength(alias); - return prefixLength > 0 - ? alias.Substring(prefixLength) + return prefixLength > 0 + ? alias.Substring(prefixLength) : alias; } @@ -36,8 +36,8 @@ internal static int GetPrefixLength(this string alias) { if (alias[0] == '-') { - return alias.Length > 1 && alias[1] == '-' - ? 2 + return alias.Length > 1 && alias[1] == '-' + ? 2 : 1; } @@ -80,7 +80,7 @@ internal static TokenizeResult Tokenize( var foundEndOfDirectives = !configuration.EnableDirectives; var argList = NormalizeRootCommand(args, configuration.RootCommand, inferRootCommand); - + var tokenList = new List(argList.Count); var knownTokens = configuration.RootCommand.ValidTokens(); @@ -88,21 +88,15 @@ internal static TokenizeResult Tokenize( for (var i = 0; i < argList.Count; i++) { var arg = argList[i]; - + if (foundDoubleDash) { - if (configuration.EnableLegacyDoubleDashBehavior) - { - tokenList.Add(Unparsed(arg)); - } - else - { - tokenList.Add(CommandArgument(arg, currentCommand!)); - } + tokenList.Add(CommandArgument(arg, currentCommand!)); + continue; } - if (!foundDoubleDash && + if (!foundDoubleDash && arg == "--") { tokenList.Add(DoubleDash()); @@ -181,8 +175,8 @@ configuration.TokenReplacer is { } replacer && } } } - else if (arg.TrySplitIntoSubtokens(out var first, out var rest) && - knownTokens.TryGetValue(first, out var subtoken) && + else if (arg.TrySplitIntoSubtokens(out var first, out var rest) && + knownTokens.TryGetValue(first, out var subtoken) && subtoken.Type == TokenType.Option) { tokenList.Add(Option(first, (Option)subtoken.Symbol!)); @@ -198,11 +192,11 @@ configuration.TokenReplacer is { } replacer && { tokenList.Add(Argument(arg)); } - + Token Argument(string value) => new(value, TokenType.Argument, default, i); Token CommandArgument(string value, Command command) => new(value, TokenType.Argument, command, i); - + Token OptionArgument(string value, Option option) => new(value, TokenType.Argument, option, i); Token Command(string value, Command cmd) => new(value, TokenType.Command, cmd, i); @@ -211,17 +205,15 @@ configuration.TokenReplacer is { } replacer && Token DoubleDash() => new("--", TokenType.DoubleDash, default, i); - Token Unparsed(string value) => new(value, TokenType.Unparsed, default, i); - Token Directive(string value) => new(value, TokenType.Directive, default, i); } return new TokenizeResult(tokenList, errorList); bool CanBeUnbundled(string arg) - => arg.Length > 2 + => arg.Length > 2 && arg[0] == '-' - && arg[1] != '-'// don't check for "--" prefixed args + && arg[1] != '-'// don't check for "--" prefixed args && arg[2] != ':' && arg[2] != '=' // handled by TrySplitIntoSubtokens && !PreviousTokenIsAnOptionExpectingAnArgument(out _); @@ -439,7 +431,7 @@ static IEnumerable SplitLine(string line) private static Dictionary ValidTokens(this Command command) { - Dictionary tokens = new (StringComparer.Ordinal); + Dictionary tokens = new(StringComparer.Ordinal); foreach (string commandAlias in command.Aliases) { diff --git a/src/System.CommandLine/Parsing/TokenType.cs b/src/System.CommandLine/Parsing/TokenType.cs index 1bb632fb31..679ba9b799 100644 --- a/src/System.CommandLine/Parsing/TokenType.cs +++ b/src/System.CommandLine/Parsing/TokenType.cs @@ -29,14 +29,7 @@ public enum TokenType /// /// A double dash (--) token, which changes the meaning of subsequent tokens. /// - /// DoubleDash, - - /// - /// A token following when is set to . - /// - /// - Unparsed, /// /// A directive token.