/// <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)); }
/// <summary> /// Determines whether the specified character is an assignment character for the <see cref="OptionStyles"/> /// currently being parsed. /// </summary> /// <param name="ch">The character to check.</param> /// <returns> /// <c>true</c> if the specified character is an assignment character for the <see cref="OptionStyles"/> /// currently being parsed; otherwise, <c>false</c>. /// </returns> private bool IsAssignmentCharacter(int ch) { OptionStyles optionStyle; return(mAssignmentCharacters.Find((char)ch, out optionStyle) && OptionStyleManager.IsAnyEnabled(optionStyle, EnabledOptionStyles) && OptionStyleManager.IsAnyEnabled(optionStyle, mCurrentOptionStyle)); }
/// <summary> /// Initializes a new instance of the <see cref="OptionNameToken"/> class. /// </summary> /// <param name="name">The name of this option.</param> /// <param name="optionStyle">The option style.</param> public OptionNameToken(string name, OptionStyles optionStyle) : base(TokenTypes.OptionNameToken, OptionStyleManager.GetPrefix(optionStyle, name) + name) { Debug.Assert(!String.IsNullOrEmpty(name)); mOptionStyle = optionStyle; mName = name; }
/// <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)); } }
/// <summary> /// Matches an option name (or names depending on the option styles enabled) preceeded by the '+' sign. /// </summary> /// <returns>An <see cref="OptionNameToken"/> representing the name (and style) of the first option /// in the sequence read.</returns> /// <remarks>This method calls <see cref="MatchGroupedOptionNames"/> if the <see cref="OptionStyles.Group"/> /// style is enabled, otherwise <see cref="MatchLongOptionName"/>.</remarks> private Token MatchPlusOption() { Debug.Assert(LA(1) == '+'); SkipCharacters(1); mCurrentOptionStyle = OptionStyles.Plus; if (OptionStyleManager.IsAllEnabled(EnabledOptionStyles, OptionStyles.Group)) { return(MatchGroupedOptionNames()); } else { return(MatchLongOptionName()); } }
/// <summary> /// Gets the next token from the input. /// </summary> /// <returns>the next token from the input or a null reference if no more tokens are available.</returns> public Token GetNextToken() { if (!mTokenQueue.IsEmpty) { return(mTokenQueue.Dequeue()); } // Cache LA(1), it will be used a lot int la1; // Skip any whitespace while ((la1 = LA(1)) != -1 && IsWhiteSpace(la1)) { ReadCharacter(); } if (la1 == -1) // No more tokens (or characters) to read { return(null); } if (la1 == '-' && OptionStyleManager.IsAnyEnabled(EnabledOptionStyles, OptionStyles.Unix)) { if (LA(2) == '-') { if (IsWhiteSpace(LA(3))) { return(MatchEndOption()); } else if (OptionStyleManager.IsAllEnabled(EnabledOptionStyles, OptionStyles.LongUnix)) { return(MatchLongUnixOption()); } } if (OptionStyleManager.IsAllEnabled(EnabledOptionStyles, OptionStyles.ShortUnix)) { return(MatchShortUnixOption()); } } if (la1 == '/' && OptionStyleManager.IsAllEnabled(EnabledOptionStyles, OptionStyles.Windows)) { return(MatchWindowsOption()); } if (la1 == '+' && OptionStyleManager.IsAllEnabled(EnabledOptionStyles, OptionStyles.Plus)) { return(MatchPlusOption()); } if (la1 == '@' && OptionStyleManager.IsAllEnabled(EnabledOptionStyles, OptionStyles.File)) { return(MatchFileOption()); } if (IsAssignmentCharacter(la1)) { return(MatchAssignmentCharacter()); } return(MatchValue()); }