mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-07-05 03:58:16 +08:00
Add support for required options
This commit is contained in:

committed by
Patrik Svensson

parent
d836ad1805
commit
67c3909bbb
@ -45,6 +45,6 @@ public sealed class CommandArgumentAttribute : Attribute
|
||||
// Assign the result.
|
||||
Position = position;
|
||||
ValueName = result.Value;
|
||||
IsRequired = result.Required;
|
||||
IsRequired = result.IsRequired;
|
||||
}
|
||||
}
|
@ -30,6 +30,11 @@ public sealed class CommandOptionAttribute : Attribute
|
||||
/// </summary>
|
||||
public bool ValueIsOptional { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value indicating whether the value is required.
|
||||
/// </summary>
|
||||
public bool IsRequired { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether this option is hidden from the help text.
|
||||
/// </summary>
|
||||
@ -39,7 +44,8 @@ public sealed class CommandOptionAttribute : Attribute
|
||||
/// Initializes a new instance of the <see cref="CommandOptionAttribute"/> class.
|
||||
/// </summary>
|
||||
/// <param name="template">The option template.</param>
|
||||
public CommandOptionAttribute(string template)
|
||||
/// <param name="isRequired">Indicates whether the option is required or not.</param>
|
||||
public CommandOptionAttribute(string template, bool isRequired = false)
|
||||
{
|
||||
if (template == null)
|
||||
{
|
||||
@ -54,6 +60,7 @@ public sealed class CommandOptionAttribute : Attribute
|
||||
ShortNames = result.ShortNames;
|
||||
ValueName = result.Value;
|
||||
ValueIsOptional = result.ValueIsOptional;
|
||||
IsRequired = isRequired;
|
||||
}
|
||||
|
||||
internal bool IsMatch(string name)
|
||||
|
Reference in New Issue
Block a user