diff --git a/src/DotNetCampus.CommandLine/CommandLineParsingOptions.cs b/src/DotNetCampus.CommandLine/CommandLineParsingOptions.cs index 251e93f..9c581f5 100644 --- a/src/DotNetCampus.CommandLine/CommandLineParsingOptions.cs +++ b/src/DotNetCampus.CommandLine/CommandLineParsingOptions.cs @@ -6,19 +6,39 @@ namespace DotNetCampus.Cli; public readonly record struct CommandLineParsingOptions { /// - public static CommandLineParsingOptions Flexible => new() { Style = CommandLineStyle.Flexible }; + public static CommandLineParsingOptions Flexible => new() + { + Style = CommandLineStyle.Flexible, + UnknownArgumentsHandling = UnknownCommandArgumentHandling.IgnoreUnknownOptionalArguments, + }; /// - public static CommandLineParsingOptions DotNet => new() { Style = CommandLineStyle.DotNet }; + public static CommandLineParsingOptions DotNet => new() + { + Style = CommandLineStyle.DotNet, + UnknownArgumentsHandling = UnknownCommandArgumentHandling.IgnoreUnknownOptionalArguments, + }; /// - public static CommandLineParsingOptions Gnu => new() { Style = CommandLineStyle.Gnu }; + public static CommandLineParsingOptions Gnu => new() + { + Style = CommandLineStyle.Gnu, + UnknownArgumentsHandling = UnknownCommandArgumentHandling.IgnoreUnknownOptionalArguments, + }; /// - public static CommandLineParsingOptions Posix => new() { Style = CommandLineStyle.Posix }; + public static CommandLineParsingOptions Posix => new() + { + Style = CommandLineStyle.Posix, + UnknownArgumentsHandling = UnknownCommandArgumentHandling.IgnoreUnknownOptionalArguments, + }; /// - public static CommandLineParsingOptions Windows => new() { Style = CommandLineStyle.Windows }; + public static CommandLineParsingOptions Windows => new() + { + Style = CommandLineStyle.Windows, + UnknownArgumentsHandling = UnknownCommandArgumentHandling.IgnoreUnknownOptionalArguments, + }; /// [Obsolete("为避免理解歧义,已弃用此名称,请使用 Windows 代替。")] diff --git a/tests/DotNetCampus.CommandLine.Tests/CommandLineStyleTestingExtensions.cs b/tests/DotNetCampus.CommandLine.Tests/CommandLineStyleTestingExtensions.cs index 4a6673d..a21fc6f 100644 --- a/tests/DotNetCampus.CommandLine.Tests/CommandLineStyleTestingExtensions.cs +++ b/tests/DotNetCampus.CommandLine.Tests/CommandLineStyleTestingExtensions.cs @@ -2,16 +2,22 @@ namespace DotNetCampus.Cli.Tests; +using UH = UnknownCommandArgumentHandling; + internal static class CommandLineStyleTestingExtensions { public static CommandLineParsingOptions ToParsingOptions(this TestCommandLineStyle style) => style switch { - TestCommandLineStyle.Flexible => CommandLineParsingOptions.Flexible, - TestCommandLineStyle.DotNet => CommandLineParsingOptions.DotNet, - TestCommandLineStyle.Gnu => CommandLineParsingOptions.Gnu, - TestCommandLineStyle.Posix => CommandLineParsingOptions.Posix, - TestCommandLineStyle.Windows => CommandLineParsingOptions.Windows, - TestCommandLineStyle.Url => CommandLineParsingOptions.Flexible with { SchemeNames = ["test"] }, + TestCommandLineStyle.Flexible => CommandLineParsingOptions.Flexible with { UnknownArgumentsHandling = UH.AllArgumentsMustBeRecognized }, + TestCommandLineStyle.DotNet => CommandLineParsingOptions.DotNet with { UnknownArgumentsHandling = UH.AllArgumentsMustBeRecognized }, + TestCommandLineStyle.Gnu => CommandLineParsingOptions.Gnu with { UnknownArgumentsHandling = UH.AllArgumentsMustBeRecognized }, + TestCommandLineStyle.Posix => CommandLineParsingOptions.Posix with { UnknownArgumentsHandling = UH.AllArgumentsMustBeRecognized }, + TestCommandLineStyle.Windows => CommandLineParsingOptions.Windows with { UnknownArgumentsHandling = UH.AllArgumentsMustBeRecognized }, + TestCommandLineStyle.Url => CommandLineParsingOptions.Flexible with + { + SchemeNames = ["test"], + UnknownArgumentsHandling = UH.AllArgumentsMustBeRecognized, + }, _ => throw new ArgumentOutOfRangeException(nameof(style), style, null), }; }