Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 25 additions & 5 deletions src/DotNetCampus.CommandLine/CommandLineParsingOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,39 @@ namespace DotNetCampus.Cli;
public readonly record struct CommandLineParsingOptions
{
/// <inheritdoc cref="CommandLineStyle.Flexible" />
public static CommandLineParsingOptions Flexible => new() { Style = CommandLineStyle.Flexible };
public static CommandLineParsingOptions Flexible => new()
{
Style = CommandLineStyle.Flexible,
UnknownArgumentsHandling = UnknownCommandArgumentHandling.IgnoreUnknownOptionalArguments,
};

/// <inheritdoc cref="CommandLineStyle.DotNet" />
public static CommandLineParsingOptions DotNet => new() { Style = CommandLineStyle.DotNet };
public static CommandLineParsingOptions DotNet => new()
{
Style = CommandLineStyle.DotNet,
UnknownArgumentsHandling = UnknownCommandArgumentHandling.IgnoreUnknownOptionalArguments,
};

/// <inheritdoc cref="CommandLineStyle.Gnu" />
public static CommandLineParsingOptions Gnu => new() { Style = CommandLineStyle.Gnu };
public static CommandLineParsingOptions Gnu => new()
{
Style = CommandLineStyle.Gnu,
UnknownArgumentsHandling = UnknownCommandArgumentHandling.IgnoreUnknownOptionalArguments,
};

/// <inheritdoc cref="CommandLineStyle.Posix" />
public static CommandLineParsingOptions Posix => new() { Style = CommandLineStyle.Posix };
public static CommandLineParsingOptions Posix => new()
{
Style = CommandLineStyle.Posix,
UnknownArgumentsHandling = UnknownCommandArgumentHandling.IgnoreUnknownOptionalArguments,
};

/// <inheritdoc cref="CommandLineStyle.Windows" />
public static CommandLineParsingOptions Windows => new() { Style = CommandLineStyle.Windows };
public static CommandLineParsingOptions Windows => new()
{
Style = CommandLineStyle.Windows,
UnknownArgumentsHandling = UnknownCommandArgumentHandling.IgnoreUnknownOptionalArguments,
};

/// <inheritdoc cref="CommandLineStyle.Windows" />
[Obsolete("为避免理解歧义,已弃用此名称,请使用 Windows 代替。")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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),
};
}
Expand Down