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 identifier switch
{ {
{ Length: >= 2 } => "--" + identifier, { Length: >= 2 } => "--" + identifier,
_ => '-' + identifier _ => '-' + identifier,
}; };
/// <summary> /// <summary>

View File

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