private OptionInfo GetInfo(OptionSpecifier opt) { int id = opt.GetId(); //Debug.Assert(id > 0 id - 1 < getNumOptions() ,"Invalid Option ID."); return(_optionInfos[id - 1]); }
public static string GetOptionHelpGroup(OptionTable opts, OptionSpecifier id) { var groupId = opts.GetOptionGroupId(id); // If not in a group, return the default help group. if (groupId == 0) { return("OPTIONS"); } // Abuse the help text of the option groups to store the "help group" // name. // // FIXME: Split out option groups. var groupHelp = opts.GetOptionHelpText(groupId); if (!string.IsNullOrEmpty(groupHelp)) { return(groupHelp); } // Otherwise keep looking. return(GetOptionHelpGroup(opts, groupId)); }
/// matches - Predicate for whether this option is part of the /// given option (which may be a group). /// /// Note that matches against options which are an alias should never be /// done -- aliases do not participate in matching and so such a query will /// always be false. public bool Matches(OptionSpecifier opt) { // Aliases are never considered in matching, look through them. var alias = GetAlias(); if (alias.IsValid()) { return(alias.Matches(opt)); } // Check exact match. if (GetId() == opt.GetId()) { return(true); } var @group = GetGroup(); if (@group.IsValid()) { return(@group.Matches(opt)); } return(false); }
public List <string> GetAllArgValues(OptionSpecifier id) { var values = new List <string>(16); AddAllArgValues(values, id); return(new List <string>(values.Select(item => item.ToString()))); }
/// ClaimAllArgs - Claim all arguments which match the given /// option id. public void ClaimAllArgs(OptionSpecifier id0) { var filteredIds = Filtered(id0); foreach (var argument in filteredIds) { argument.Claim(); } }
/// AddLastArg - Render only the last argument match \p Id0, if present. public void AddLastArg(List <string> output, OptionSpecifier id0) { var a = GetLastArg(id0); if (a != null) { a.Claim(); a.Render(this, output); } }
public string GetLastArgValue(OptionSpecifier id, string Default = "") { var a = GetLastArg(id); if (a != null) { return(a.GetValue()); } return(Default); }
public bool HasFlag(OptionSpecifier pos, OptionSpecifier neg, bool Default = true) { var a = GetLastArg(pos, neg); if (a != null) { return(a.GetOption().Matches(pos)); } return(Default); }
public Option GetOption(OptionSpecifier opt) { var id = opt.GetId(); if (id == 0) { return(new Option(null, null)); } Debug.Assert((id - 1) < GetNumOptions(), "Invalid ID."); return(new Option(GetInfo(id), this)); }
/// AddAllArgValues - Render the argument values of all arguments /// matching the given ids. public void AddAllArgValues(List <string> output, OptionSpecifier id0, OptionSpecifier id1 = null, OptionSpecifier id2 = null) { var filteredIds = Filtered(id0, id1, id2); foreach (var argument in filteredIds) { argument.Claim(); var values = argument.GetValues(); output.AddRange(values); } }
/// AddAllArgs - Render all arguments matching the given ids. public void AddAllArgs(List <string> output, OptionSpecifier id0, OptionSpecifier id1 = null, OptionSpecifier id2 = null) { var filteredIds = Filtered(id0, id1, id2); foreach (var argument in filteredIds) { argument.Claim(); argument.Render(this, output); } }
/// AddAllArgsTranslated - Render all the arguments matching the /// given ids, but forced to separate args and using the provided /// name instead of the first option value. /// /// \param Joined - If true, render the argument as joined with /// the option specifier. public void AddAllArgsTranslated(List <string> output, OptionSpecifier id0, string translation, bool joined = false) { var filteredIds = Filtered(id0); foreach (var argument in filteredIds) { argument.Claim(); if (joined) { output.Add(MakeArgString(translation + argument.GetValue())); } else { output.Add(translation); output.Add(argument.GetValue()); } } }
public static string GetOptionHelpName(OptionTable opts, OptionSpecifier id) { var o = opts.GetOption(id); var name = o.GetPrefixedName(); string metaVarName; // Add metavar, if used. var kind = o.GetKind(); if (kind == OptionKind.GroupClass || kind == OptionKind.InputClass || kind == OptionKind.UnknownClass) { throw new Exception("Invalid option with help text."); } if (kind == OptionKind.MultiArgClass) { metaVarName = opts.GetOptionMetaVar(id); if (!string.IsNullOrEmpty(metaVarName)) { // For MultiArgs, metavar is full list of all argument names. name += ' '; name += metaVarName; } else { // For MultiArgs<N>, if metavar not supplied, print <value> N times. for (int i = 0, e = o.GetNumArgs(); i < e; ++i) { name += " <value>"; } } } else if (kind == OptionKind.FlagClass) { } else if (kind == OptionKind.ValuesClass) { } else if (kind == OptionKind.SeparateClass || kind == OptionKind.JoinedOrSeparateClass || kind == OptionKind.RemainingArgsClass || kind == OptionKind.RemainingArgsJoinedClass) { name += ' '; metaVarName = opts.GetOptionMetaVar(id); if (!string.IsNullOrEmpty(metaVarName)) { name += metaVarName; } else { name += "<value>"; } } else if (kind == OptionKind.JoinedClass || kind == OptionKind.CommaJoinedClass || kind == OptionKind.JoinedAndSeparateClass) { metaVarName = opts.GetOptionMetaVar(id); if (!string.IsNullOrEmpty(metaVarName)) { name += metaVarName; } else { name += "<value>"; } } return(name); }
public string GetOptionMetaVar(OptionSpecifier id) { return(GetInfo(id).MetaVar); }
public string GetOptionHelpText(OptionSpecifier id) { return(GetInfo(id).HelpText); }
public int GetOptionGroupId(OptionSpecifier id) { return(GetInfo(id).GroupId); }
public int GetOptionKind(OptionSpecifier id) { return(GetInfo(id).Kind); }
public string GetOptionName(OptionSpecifier id) { return(GetInfo(id).Name); }
public void EraseArg(OptionSpecifier id) { _optRanges.Remove(id.GetId()); }