void ProcessOption(CLOption option, String[] args, Boolean optionIsLastOrAlone, ref Int32 originalArgIndex) { // Check for duplicates if (option.set) { throw new CommandLineException(String.Format("Found option '{0}' twice", option)); } option.set = true; if (option.hasArg) { if (!optionIsLastOrAlone) { throw new CommandLineException(String.Format("Option '{0}' requires an argument but it is not the last letter in a list of options", option)); } originalArgIndex++; if (originalArgIndex >= args.Length) { throw new CommandLineException(String.Format("Option '{0}' requires an argument but there was none", option)); } option.ParseArg(args[originalArgIndex]); } }
public void Add(CLOption option) { if (option.letter == '\0' && option.name == null) { throw new ArgumentException(String.Format("Option '{0}' has a null letter and name", option), "option"); } CLOption otherOption; if (option.letter != '\0') { if (optionLetters.TryGetValue(option.letter, out otherOption)) { throw new InvalidOperationException(String.Format("You've added two options with same letter '{0}' ({1}) and ({2})", option.letter, otherOption, option)); } optionLetters.Add(option.letter, option); } if (option.name != null) { if (optionNames.TryGetValue(option.name, out otherOption)) { throw new InvalidOperationException(String.Format("You've added two options with same name '{0}' ({1}) and ({2})", option.name, otherOption, option)); } optionNames.Add(option.name, option); } this.options.Add(option); // // Update maximum usage left column length // if (option.usageLeftColumn.Length > maxUsageLeftColumnWidth) { maxUsageLeftColumnWidth = option.usageLeftColumn.Length; if (maxUsageLeftColumnWidth >= bufferWidth - 40) { bufferWidth = maxUsageLeftColumnWidth + 40; } } }