/** * Appends the usage clause for an OptionGroup to a StringBuffer. * The clause is wrapped in square brackets if the group is required. * The display of the options is handled by appendOption * @param buff the StringBuffer to append to * @param group the group to append * @see #appendOption(StringBuffer,Option,boolean) */ private void AppendOptionGroup(StringBuilder buff, OptionGroup group) { if (!group.IsRequired()) { buff.Append("["); } List <Option> optList = new List <Option>(group.GetOptions()); if (GetOptionComparator() != null) { optList.Sort(GetOptionComparator()); } foreach (Option option in optList) { // whether the option is required or not is handled at group level AppendOption(buff, option, true); if (optList.IndexOf(option) < optList.Count - 1) { buff.Append(" | "); } } if (!group.IsRequired()) { buff.Append("]"); } }
/** * Add the specified option group. * * @param group the OptionGroup that is to be added * @return the resulting Options instance */ public Options AddOptionGroup(OptionGroup group) { if (group.IsRequired()) { requiredOpts.Add(group); } foreach (Option option in group.GetOptions()) { // an Option cannot be required if it is in an // OptionGroup, either the group is required or // nothing is required option.SetRequired(false); AddOption(option); optionGroups.Add(option.GetKey(), group); } return(this); }
/** * Removes the option or its group from the list of expected elements. * * @param option */ private void UpdateRequiredOptions(Option option) { if (option.IsRequired()) { expectedOpts.Remove(option.GetKey()); } // if the option is in an OptionGroup make that option the selected option of the group if (options.GetOptionGroup(option) != null) { OptionGroup group = options.GetOptionGroup(option); if (group.IsRequired()) { expectedOpts.Remove(group); } group.SetSelected(option); } }