public CommaJoinedOption( OptSpecifier id, IReadOnlyList <string> prefixes, string name, string helpText = null, OptSpecifier?aliasId = null, OptSpecifier?groupId = null, string metaVar = null) : base(id, prefixes, name, helpText: helpText, metaVar: metaVar, aliasId: aliasId, groupId: groupId) { if (!id.IsValid) { throw new ArgumentException("Invalid id"); } if (prefixes == null) { throw new ArgumentNullException(nameof(prefixes)); } if (prefixes.Count == 0) { throw new ArgumentException("At least one prefix must be specified"); } if (prefixes.Any(string.IsNullOrWhiteSpace)) { throw new ArgumentException("All prefixes must be non-empty"); } if (name == null) { throw new ArgumentNullException(nameof(name)); } }
public MultiArgOption( OptSpecifier id, string prefix, string name, int argCount, string helpText = null, OptSpecifier?aliasId = null, OptSpecifier?groupId = null, string metaVar = null) : base(id, prefix, name, helpText: helpText, metaVar: metaVar, aliasId: aliasId, groupId: groupId) { if (!id.IsValid) { throw new ArgumentException("Invalid id"); } if (prefix == null) { throw new ArgumentNullException(nameof(prefix)); } if (string.IsNullOrWhiteSpace(prefix)) { throw new ArgumentException("Contract violated: !string.IsNullOrWhiteSpace(prefix)"); } if (name == null) { throw new ArgumentNullException(nameof(name)); } if (argCount <= 0) { throw new ArgumentOutOfRangeException(nameof(argCount), "Contract violated: argCount > 0"); } ArgCount = argCount; }
public RemainingArgsOption( OptSpecifier id, string prefix, string name, string helpText = null, OptSpecifier?aliasId = null, OptSpecifier?groupId = null, string metaVar = null) : base(id, prefix, name, helpText: helpText, metaVar: metaVar, aliasId: aliasId, groupId: groupId) { if (!id.IsValid) { throw new ArgumentException("Invalid id"); } if (prefix == null) { throw new ArgumentNullException(nameof(prefix)); } if (string.IsNullOrWhiteSpace(prefix)) { throw new ArgumentException("Contract violated: !string.IsNullOrWhiteSpace(prefix)"); } if (name == null) { throw new ArgumentNullException(nameof(name)); } }
internal Option( OptSpecifier id, string name, OptSpecifier?aliasId = null, OptSpecifier?groupId = null, string helpText = null, string metaVar = null) { if (!id.IsValid) { throw new ArgumentException("Invalid id"); } if (name == null) { throw new ArgumentNullException(nameof(name)); } Id = id.Id; prefixes = new string[0]; this.name = name; this.aliasId = aliasId.GetValueOrDefault().Id; this.groupId = groupId.GetValueOrDefault().Id; HelpText = helpText; MetaVar = metaVar; }
public CommaJoinedOption( OptSpecifier id, string prefix, string name, string helpText = null, OptSpecifier?aliasId = null, OptSpecifier?groupId = null, string metaVar = null) : base(id, prefix, name, helpText: helpText, metaVar: metaVar, aliasId: aliasId, groupId: groupId) { if (!id.IsValid) { throw new ArgumentException("Invalid id"); } if (prefix == null) { throw new ArgumentNullException(nameof(prefix)); } if (string.IsNullOrWhiteSpace(prefix)) { throw new ArgumentException("Prefix must not be empty."); } if (name == null) { throw new ArgumentNullException(nameof(name)); } }
public JoinedAndSeparateOption( OptSpecifier id, IReadOnlyList <string> prefixes, string name, string helpText = null, OptSpecifier?aliasId = null, OptSpecifier?groupId = null, string metaVar = null) : base(id, prefixes, name, helpText: helpText, metaVar: metaVar, aliasId: aliasId, groupId: groupId) { if (!id.IsValid) { throw new ArgumentException("Invalid id"); } if (prefixes == null) { throw new ArgumentNullException(nameof(prefixes)); } if (prefixes.Count == 0) { throw new ArgumentException("Contract violated: prefixes.Count != 0"); } if (prefixes.Any(string.IsNullOrWhiteSpace)) { throw new ArgumentException("Contract violated: !string.IsNullOrWhiteSpace(prefix)"); } if (name == null) { throw new ArgumentNullException(nameof(name)); } }
public static OptTableBuilder AddUnknown(this OptTableBuilder builder, OptSpecifier id) { if (!id.IsValid) { throw new ArgumentException("Invalid id"); } builder.Add(new UnknownOption(id.Id)); return(builder); }
public string GetLastArgValue(OptSpecifier id, string defaultValue = null) { Arg lastArg = GetLastArg(id); if (lastArg == null) { return(defaultValue); } return(lastArg.Value); }
public bool GetFlag(OptSpecifier id, bool defaultValue = false) { Arg arg = GetLastArg(id); if (arg != null) { return(arg.Option.Matches(id)); } return(defaultValue); }
public void ClaimAllArgs(OptSpecifier id) { foreach (var arg in args) { if (arg.Option.Matches(id)) { arg.Claim(); } } }
public bool GetFlagNoClaim( OptSpecifier positiveId, OptSpecifier negativeId, bool defaultValue = false) { Arg arg = GetLastArgNoClaim(positiveId, negativeId); if (arg != null) { return(arg.Option.Matches(positiveId)); } return(defaultValue); }
public Arg GetLastArgNoClaim(OptSpecifier id) { for (int i = args.Count - 1; i >= 0; --i) { var arg = args[i]; if (arg.Option.Matches(id)) { return(arg); } } return(null); }
/// <summary> /// Gets the <see cref="Option"/> for the specified id. /// </summary> /// <param name="id"> /// The id of the option to get. /// </param> /// <returns> /// The specified <see cref="Option"/> or <see langword="null"/> if no /// such option exists. /// </returns> public Option GetOption(OptSpecifier id) { if (!id.IsValid) { return(null); } if (!optionMap.TryGetValue(id.Id, out var opt)) { return(null); } return(opt); }
public Arg GetLastArg(OptSpecifier id) { Arg lastArg = null; foreach (var arg in args) { if (arg.Option.Matches(id)) { arg.Claim(); lastArg = arg; } } return(lastArg); }
public IList <string> GetAllArgValues(OptSpecifier id) { var allValues = new List <string>(); foreach (var arg in args) { if (arg.Option.Matches(id)) { arg.Claim(); allValues.AddRange(arg.Values); } } return(allValues); }
public UnknownOption( OptSpecifier id, string helpText = null, OptSpecifier?aliasId = null, OptSpecifier?groupId = null, string metaVar = null) : base(id, "<unknown>", helpText: helpText, metaVar: metaVar, aliasId: aliasId, groupId: groupId) { if (!id.IsValid) { throw new ArgumentException("Invalid id"); } Kind = OptionKind.Unknown; }
public static OptTableBuilder AddGroup( this OptTableBuilder builder, OptSpecifier id, string name, string helpText = null, string metaVar = null) { var option = new GroupOption( id.Id, name, helpText: helpText, metaVar: metaVar); builder.Add(option); return(builder); }
public GroupOption( OptSpecifier id, string name, string helpText = null, string metaVar = null) : base(id, name, helpText: helpText, metaVar: metaVar) { if (!id.IsValid) { throw new ArgumentException("Invalid id"); } if (name == null) { throw new ArgumentNullException(nameof(name)); } Kind = OptionKind.Group; }
public static OptTableBuilder AddSeparate( this OptTableBuilder builder, OptSpecifier id, IReadOnlyList <string> prefixes, string name, string helpText = null, string metaVar = null, OptSpecifier?aliasId = null, OptSpecifier?groupId = null) { if (!id.IsValid) { throw new ArgumentException("Invalid id"); } if (prefixes == null) { throw new ArgumentNullException(nameof(prefixes)); } if (prefixes.Count == 0) { throw new ArgumentException("Contract violated: prefixes.Count != 0"); } if (prefixes.Any(string.IsNullOrWhiteSpace)) { throw new ArgumentException("Contract violated: !string.IsNullOrWhiteSpace(prefix)"); } if (name == null) { throw new ArgumentNullException(nameof(name)); } var option = new SeparateOption( id.Id, prefixes, name, helpText: helpText, metaVar: metaVar, aliasId: aliasId, groupId: groupId); builder.Add(option); return(builder); }
protected Option( OptSpecifier id, IReadOnlyList <string> prefixes, string name, OptSpecifier?aliasId = null, OptSpecifier?groupId = null, string helpText = null, string metaVar = null, int flags = 0) { if (!id.IsValid) { throw new ArgumentException("Invalid id"); } if (prefixes == null) { throw new ArgumentNullException(nameof(prefixes)); } if (prefixes.Count == 0) { throw new ArgumentException("Contract violated: prefixes.Count != 0"); } if (prefixes.Any(string.IsNullOrWhiteSpace)) { throw new ArgumentException("Contract violated: !string.IsNullOrWhiteSpace(prefix)"); } if (name == null) { throw new ArgumentNullException(nameof(name)); } Id = id.Id; this.prefixes = prefixes.ToArray(); this.name = name; this.aliasId = aliasId.GetValueOrDefault().Id; this.groupId = groupId.GetValueOrDefault().Id; HelpText = helpText; MetaVar = metaVar; Flags = flags; }
public static OptTableBuilder AddJoinedOrSeparate( this OptTableBuilder builder, OptSpecifier id, string prefix, string name, string helpText = null, string metaVar = null, OptSpecifier?aliasId = null, OptSpecifier?groupId = null) { var option = new JoinedOrSeparateOption( id.Id, prefix, name, helpText: helpText, metaVar: metaVar, aliasId: aliasId, groupId: groupId); builder.Add(option); return(builder); }
public static OptTableBuilder AddRemainingArgs( this OptTableBuilder builder, OptSpecifier id, IReadOnlyList <string> prefixes, string name, string helpText = null, string metaVar = null, OptSpecifier?aliasId = null, OptSpecifier?groupId = null) { var option = new RemainingArgsOption( id.Id, prefixes, name, helpText: helpText, metaVar: metaVar, aliasId: aliasId, groupId: groupId); builder.Add(option); return(builder); }
public static OptTableBuilder AddJoined( this OptTableBuilder builder, OptSpecifier id, string prefix, string name, string helpText = null, string metaVar = null, OptSpecifier?aliasId = null, OptSpecifier?groupId = null) { if (!id.IsValid) { throw new ArgumentException("Invalid id"); } if (prefix == null) { throw new ArgumentNullException(nameof(prefix)); } if (string.IsNullOrWhiteSpace(prefix)) { throw new ArgumentException("Contract violated: !string.IsNullOrWhiteSpace(prefix)"); } if (name == null) { throw new ArgumentNullException(nameof(name)); } var option = new JoinedOption( id.Id, prefix, name, helpText: helpText, metaVar: metaVar, aliasId: aliasId, groupId: groupId); builder.Add(option); return(builder); }
public virtual bool Matches(OptSpecifier opt) { Option alias = Alias; if (alias != null) { return(alias.Matches(opt)); } if (opt.Id == Id) { return(true); } Option group = Group; if (group != null) { return(group.Matches(opt)); } return(false); }
public static OptTableBuilder AddMultiArg( this OptTableBuilder builder, OptSpecifier id, IReadOnlyList <string> prefixes, string name, int argumentCount, string helpText = null, string metaVar = null, OptSpecifier?aliasId = null, OptSpecifier?groupId = null) { var option = new MultiArgOption( id.Id, prefixes, name, argumentCount, helpText: helpText, metaVar: metaVar, aliasId: aliasId, groupId: groupId); builder.Add(option); return(builder); }
protected Option( OptSpecifier id, string prefix, string name, OptSpecifier?aliasId = null, OptSpecifier?groupId = null, string helpText = null, string metaVar = null, int flags = 0) { if (!id.IsValid) { throw new ArgumentException("Invalid id"); } if (prefix == null) { throw new ArgumentNullException(nameof(prefix)); } if (string.IsNullOrWhiteSpace(prefix)) { throw new ArgumentException("Contract violated: !string.IsNullOrWhiteSpace(prefix)"); } if (name == null) { throw new ArgumentNullException(nameof(name)); } Id = id.Id; prefixes = new[] { prefix }; this.name = name; HelpText = helpText; MetaVar = metaVar; this.aliasId = aliasId.GetValueOrDefault().Id; this.groupId = groupId.GetValueOrDefault().Id; Flags = flags; }
public bool HasArg(OptSpecifier id) { return(GetLastArg(id) != null); }
public IEnumerable <Arg> Matching(OptSpecifier id) { return(args.Where(arg => arg.Option.Matches(id))); }
public void RemoveAllArgs(OptSpecifier id) { args.RemoveAll(a => a.Option.Matches(id)); }