This commit is contained in:
Tyrrrz
2024-11-12 22:42:55 +02:00
parent 2cb9335e25
commit 20481d4e24
2 changed files with 16 additions and 17 deletions

View File

@@ -16,7 +16,7 @@ public class CommandOptionToken(string identifier, IReadOnlyList<string> values)
identifier switch
{
{ Length: >= 2 } => "--" + identifier,
_ => '-' + identifier
_ => '-' + identifier,
};
/// <summary>

View File

@@ -143,26 +143,25 @@ internal static class CommandInputSchemaExtensions
{
CommandParameterSchema => "Parameter",
CommandOptionSchema => "Option",
_ => throw new InvalidOperationException("Unknown input schema type.")
_ => throw new InvalidOperationException("Unknown input schema type."),
};
public static string GetFormattedIdentifier(this CommandInputSchema schema) =>
schema switch
{
CommandParameterSchema parameter
=> parameter.IsSequence ? $"<{parameter.Name}>" : $"<{parameter.Name}...>",
CommandOptionSchema option
=> option switch
{
{ Name: not null, ShortName: not null }
=> $"-{option.ShortName}|--{option.Name}",
{ Name: not null } => $"--{option.Name}",
{ ShortName: not null } => $"-{option.ShortName}",
_
=> throw new InvalidOperationException(
"Option must have a name or a short name."
)
},
_ => throw new ArgumentOutOfRangeException(nameof(schema))
CommandParameterSchema parameter => parameter.IsSequence
? $"<{parameter.Name}>"
: $"<{parameter.Name}...>",
CommandOptionSchema option => option switch
{
{ Name: not null, ShortName: not null } => $"-{option.ShortName}|--{option.Name}",
{ Name: not null } => $"--{option.Name}",
{ ShortName: not null } => $"-{option.ShortName}",
_ => throw new InvalidOperationException(
"Option must have a name or a short name."
),
},
_ => throw new ArgumentOutOfRangeException(nameof(schema)),
};
}