using System;
using System.Collections.Generic;
namespace AMWD.Common.Cli
{
///
/// Represents a named option.
///
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
public class Option
{
///
/// Initialises a new instance of the class.
///
/// The primary name of the option.
/// The number of additional parameters for this option.
internal Option(string name, int parameterCount)
{
Names = [name];
ParameterCount = parameterCount;
}
///
/// Gets the names of this option.
///
public List Names { get; private set; }
///
/// Gets the number of additional parameters for this option.
///
public int ParameterCount { get; private set; }
///
/// Gets a value indicating whether this option is required.
///
public bool IsRequired { get; private set; }
///
/// Gets a value indicating whether this option can only be specified once.
///
public bool IsSingle { get; private set; }
///
/// Gets the action to invoke when the option is set.
///
public Action Action { get; private set; }
///
/// Gets a value indicating whether this option is set in the command line.
///
public bool IsSet { get; internal set; }
///
/// Gets the number of times that this option is set in the command line.
///
public int SetCount { get; internal set; }
///
/// Gets the instance that contains additional parameters set
/// for this option.
///
public Argument Argument { get; internal set; }
///
/// Gets the value of the instance for this option.
///
public string Value => Argument?.Value;
///
/// Sets alias names for this option.
///
/// The alias names for this option.
/// The current instance.
public Option Alias(params string[] names)
{
Names.AddRange(names);
return this;
}
///
/// Marks this option as required. If a required option is not set in the command line,
/// an exception is thrown on parsing.
///
/// The current instance.
public Option Required()
{
IsRequired = true;
return this;
}
///
/// Marks this option as single. If a single option is set multiple times in the
/// command line, an exception is thrown on parsing.
///
/// The current instance.
public Option Single()
{
IsSingle = true;
return this;
}
///
/// Sets the action to invoke when the option is set.
///
/// The action to invoke when the option is set.
/// The current instance.
public Option Do(Action action)
{
Action = action;
return this;
}
}
}