using System; namespace Unosquare.Swan.Attributes { /// /// Models an option specification. /// Based on CommandLine (Copyright 2005-2015 Giacomo Stelluti Scala and Contributors.). /// [AttributeUsage(AttributeTargets.Property)] public sealed class ArgumentOptionAttribute : Attribute { /// /// Initializes a new instance of the class. /// The default long name will be inferred from target property. /// public ArgumentOptionAttribute() : this(String.Empty, String.Empty) { } /// /// Initializes a new instance of the class. /// /// The long name of the option. public ArgumentOptionAttribute(String longName) : this(String.Empty, longName) { } /// /// Initializes a new instance of the class. /// /// The short name of the option. /// The long name of the option or null if not used. public ArgumentOptionAttribute(Char shortName, String longName) : this(new String(shortName, 1), longName) { } /// /// Initializes a new instance of the class. /// /// The short name of the option.. public ArgumentOptionAttribute(Char shortName) : this(new String(shortName, 1), String.Empty) { } private ArgumentOptionAttribute(String shortName, String longName) { this.ShortName = shortName ?? throw new ArgumentNullException(nameof(shortName)); this.LongName = longName ?? throw new ArgumentNullException(nameof(longName)); } /// /// Gets long name of this command line option. This name is usually a single English word. /// /// /// The long name. /// public String LongName { get; } /// /// Gets a short name of this command line option, made of one character. /// /// /// The short name. /// public String ShortName { get; } /// /// When applying attribute to target properties, /// it allows you to split an argument and consume its content as a sequence. /// public Char Separator { get; set; } = '\0'; /// /// Gets or sets mapped property default value. /// /// /// The default value. /// public Object DefaultValue { get; set; } /// /// Gets or sets a value indicating whether a command line option is required. /// /// /// true if required; otherwise, false. /// public Boolean Required { get; set; } /// /// Gets or sets a short description of this command line option. Usually a sentence summary. /// /// /// The help text. /// public String HelpText { get; set; } } }