mirror of
https://github.com/spectreconsole/spectre.console.git
synced 2025-10-25 15:19:23 +00:00
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
36 lines
1.4 KiB
C#
36 lines
1.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Reflection;
|
|
|
|
namespace Spectre.Console.Cli
|
|
{
|
|
internal sealed class CommandOption : CommandParameter
|
|
{
|
|
public IReadOnlyList<string> LongNames { get; }
|
|
public IReadOnlyList<string> ShortNames { get; }
|
|
public string? ValueName { get; }
|
|
public bool ValueIsOptional { get; }
|
|
public bool IsShadowed { get; set; }
|
|
|
|
public CommandOption(
|
|
Type parameterType, ParameterKind parameterKind, PropertyInfo property, string? description,
|
|
TypeConverterAttribute? converter, PairDeconstructorAttribute? deconstructor,
|
|
CommandOptionAttribute optionAttribute, ParameterValueProviderAttribute? valueProvider,
|
|
IEnumerable<ParameterValidationAttribute> validators,
|
|
DefaultValueAttribute? defaultValue, bool valueIsOptional)
|
|
: base(parameterType, parameterKind, property, description, converter,
|
|
defaultValue, deconstructor, valueProvider, validators, false, optionAttribute.IsHidden)
|
|
{
|
|
LongNames = optionAttribute.LongNames;
|
|
ShortNames = optionAttribute.ShortNames;
|
|
ValueName = optionAttribute.ValueName;
|
|
ValueIsOptional = valueIsOptional;
|
|
}
|
|
|
|
public string GetOptionName()
|
|
{
|
|
return LongNames.Count > 0 ? LongNames[0] : ShortNames[0];
|
|
}
|
|
}
|
|
} |