private bool ProcessOption(OptionRecord rec) { var foundOption = FindOption(rec); if (!foundOption) { // In case we have an option named "-1" and int value -1. This causes confusion. return(ProcessCommandOrOptionValue(rec)); } return(true); }
private bool FindOption(OptionRecord rec) { var context = CurrentContext; while (context != null) { foreach (var option in context.CurrentCommand.Options) { if (!rec.Name.EqualsIgnoreCase(rec.IsLongOption ? option.LongName : option.ShortName)) { continue; } if (results.ContainsKey(option)) { if (option.AllowMultipleValues) { context.AssertSafeToSwitchProcessingContext(); context.CurrentOption = option; return(true); } continue; } context.AssertSafeToSwitchProcessingContext(); context.CurrentOption = option; var argumentModel = new ArgumentModel(rec.Name, rec.Value); results.Add(option, argumentModel); return(true); } if (ProcessClusteredOptions(context, rec)) { return(true); } context = context.Parent; } return(false); }
private bool ProcessClusteredOptions(ProcessingContext context, OptionRecord rec) { var tokens = rec.Name.WithoutPreAndPostfixes(options); var list = new List <ICommandLineOption>(); foreach (var token in tokens) { bool found = false; string key = $"{options.PrefixShortOption}{token}"; foreach (var option in context.CurrentCommand.Options.Where(ValidClusteredOption)) { if (!option.ShortName.EqualsIgnoreCase(key)) { continue; } var model = new ArgumentModel(key); list.Add(option); results.Add(option, model); found = true; break; } if (!found) { return(false); } } context.NextArgumentIsForClusteredOptions = true; context.ProcessedClusteredOptions = list; return(true); }