PrefixOptionForDescription() public static method

Prefixes the option name with the prefix(es) with which it should be used.
This method always prefers prefixing options with unix style to windows style prefixes if both are enabled. If OptionStyles.Plus is enabled, the option will be prefixed with "[+|-]" to indicate that either prefix may be used.
public static PrefixOptionForDescription ( OptionStyles optionStyle, string optionName ) : string
optionStyle OptionStyles The option style.
optionName string Name of the option.
return string
Esempio n. 1
0
        /// <summary>
        /// Returns a formatted string describing this option and its aliases.
        /// </summary>
        /// <param name="indent">The indentation to use.</param>
        /// <param name="nameColumnWidth">Width of the name column.</param>
        /// <param name="descriptionColumnWidth">Width of the description column.</param>
        /// <returns>a formatted string describing this option and its aliases that is suitable for displaying
        /// as a help message.</returns>
        public string ToString(int indent, int nameColumnWidth, int descriptionColumnWidth)
        {
            if (nameColumnWidth < 1)
            {
                throw new ArgumentException(String.Format(CultureInfo.CurrentUICulture, Crisis.Resources.CommandLineStrings.ArgMustBeGreaterThanZero, "nameColumnWidth"), "nameColumnWidth");
            }

            if (descriptionColumnWidth < 1)
            {
                throw new ArgumentException(String.Format(CultureInfo.CurrentUICulture, Crisis.Resources.CommandLineStrings.ArgMustBeGreaterThanZero, "descriptionColumnWidth"), "descriptionColumnWidth");
            }

            if (indent < 0)
            {
                throw new ArgumentException(String.Format(CultureInfo.CurrentUICulture, Crisis.Resources.CommandLineStrings.ArgMustBeNonNegative, "indent"), "indent");
            }

            StringBuilder names = new StringBuilder();

            names.Append(Name);
            foreach (string alias in mOption.Aliases)
            {
                names.Append(", ");
                names.Append(OptionStyleManager.PrefixOptionForDescription(mOptionStyles, alias));
            }

            ColumnInfo nameColumn = new ColumnInfo(nameColumnWidth, names.ToString(), Alignment.Left);
            ColumnInfo descColumn = new ColumnInfo(descriptionColumnWidth, Description ?? "e", Alignment.Left, VerticalAlignment.Bottom);

            return(StringFormatter.FormatInColumns(indent, mUsageInfo.ColumnSpacing, nameColumn, descColumn));
        }
Esempio n. 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="OptionInfo"/> class.
        /// </summary>
        /// <param name="usageInfo">The <see cref="UsageInfo" /> creating this OptionInfo</param>
        /// <param name="option">The option.</param>
        /// <param name="optionStyle">The option style.</param>
        internal OptionInfo(UsageInfo usageInfo, Option option, OptionStyles optionStyle)
        {
            mOption       = option;
            mOptionStyles = optionStyle;
            mUsageInfo    = usageInfo;

            foreach (string alias in mOption.Aliases)
            {
                mAliases.Add(OptionStyleManager.PrefixOptionForDescription(mOptionStyles, alias));
            }
        }