mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-12-21 09:35:47 +08:00
Added the ability to hide CommandOptions. (#642)
CommandOptions now has an IsHidden property that, when set to true, will cause the option to be hidden from the following cases: - Help text using `-h|--help` - Xml representations generated with the `cli xml` command - Diagnostics displayed with the `cli explain` command Hidden options can still be outputted with `cli explain` using the `--hidden` option that is also used to display hidden commands. Fixes #631
This commit is contained in:
@@ -16,7 +16,7 @@ namespace Spectre.Console.Cli
|
||||
CommandArgumentAttribute argument, ParameterValueProviderAttribute? valueProvider,
|
||||
IEnumerable<ParameterValidationAttribute> validators)
|
||||
: base(parameterType, parameterKind, property, description, converter, defaultValue,
|
||||
null, valueProvider, validators, argument.IsRequired)
|
||||
null, valueProvider, validators, argument.IsRequired, false)
|
||||
{
|
||||
Value = argument.ValueName;
|
||||
Position = argument.Position;
|
||||
|
||||
@@ -20,7 +20,7 @@ namespace Spectre.Console.Cli
|
||||
IEnumerable<ParameterValidationAttribute> validators,
|
||||
DefaultValueAttribute? defaultValue, bool valueIsOptional)
|
||||
: base(parameterType, parameterKind, property, description, converter,
|
||||
defaultValue, deconstructor, valueProvider, validators, false)
|
||||
defaultValue, deconstructor, valueProvider, validators, false, optionAttribute.IsHidden)
|
||||
{
|
||||
LongNames = optionAttribute.LongNames;
|
||||
ShortNames = optionAttribute.ShortNames;
|
||||
|
||||
@@ -19,6 +19,7 @@ namespace Spectre.Console.Cli
|
||||
public List<ParameterValidationAttribute> Validators { get; }
|
||||
public ParameterValueProviderAttribute? ValueProvider { get; }
|
||||
public bool Required { get; set; }
|
||||
public bool IsHidden { get; }
|
||||
public string PropertyName => Property.Name;
|
||||
|
||||
public virtual bool WantRawValue => ParameterType.IsPairDeconstructable()
|
||||
@@ -30,7 +31,7 @@ namespace Spectre.Console.Cli
|
||||
DefaultValueAttribute? defaultValue,
|
||||
PairDeconstructorAttribute? deconstructor,
|
||||
ParameterValueProviderAttribute? valueProvider,
|
||||
IEnumerable<ParameterValidationAttribute> validators, bool required)
|
||||
IEnumerable<ParameterValidationAttribute> validators, bool required, bool isHidden)
|
||||
{
|
||||
Id = Guid.NewGuid();
|
||||
ParameterType = parameterType;
|
||||
@@ -43,6 +44,7 @@ namespace Spectre.Console.Cli
|
||||
ValueProvider = valueProvider;
|
||||
Validators = new List<ParameterValidationAttribute>(validators ?? Array.Empty<ParameterValidationAttribute>());
|
||||
Required = required;
|
||||
IsHidden = isHidden;
|
||||
}
|
||||
|
||||
public bool IsFlagValue()
|
||||
|
||||
Reference in New Issue
Block a user