Example #1
0
 /// <summary>
 ///     Sets the <see cref="OptionBuilder{T}.DefaultFactory"/> in the option builder.
 /// </summary>
 /// <typeparam name="T">Type of the option.</typeparam>
 /// <param name="builder">Source builder.</param>
 /// <param name="defaultFactory">Default value factory to be used for the option's argument.</param>
 /// <returns><paramref name="builder"/>, to allow chaining.</returns>
 /// <exception cref="ArgumentNullException"><paramref name="builder"/> is <see langword="null"/>.</exception>
 public static OptionBuilder <T> GetDefaultFrom <T>(this OptionBuilder <T> builder, Func <T> defaultFactory)
 {
     (builder ?? throw Exceptions.BuildArgumentNull(nameof(builder)))
     .DefaultFactory = defaultFactory ?? throw Exceptions.BuildArgumentNull(nameof(defaultFactory));
     return(builder);
 }
Example #2
0
 /// <inheritdoc/>
 protected override void SetItem(int index, ValidateSymbol <CommandResult> item)
 {
     base.SetItem(index, item ?? throw Exceptions.BuildArgumentNull(nameof(item)));
 }
Example #3
0
 public static OptionBuilder <T> SetArity <T>(this OptionBuilder <T> builder, IArgumentArity?arity)
 {
     (builder ?? throw Exceptions.BuildArgumentNull(nameof(builder)))
     .Arity = arity;
     return(builder);
 }
Example #4
0
 /// <inheritdoc/>
 /// <exception cref="ArgumentNullException"><paramref name="item"/> is <see langword="null"/>.</exception>
 protected override void InsertItem(int index, IOptionBuilder item)
 {
     base.InsertItem(index, item ?? throw Exceptions.BuildArgumentNull(nameof(item)));
 }
Example #5
0
 /// <inheritdoc/>
 /// <exception cref="ArgumentNullException"><paramref name="item"/> is <see langword="null"/>.</exception>
 protected override void SetItem(int index, Action <Option> item)
 {
     base.SetItem(index, item ?? throw Exceptions.BuildArgumentNull(nameof(item)));
 }
Example #6
0
 public static ArgumentBuilder <T> AddSuggestions <T>(this ArgumentBuilder <T> builder, SuggestDelegate suggestionsSource)
 {
     return((builder ?? throw Exceptions.BuildArgumentNull(nameof(builder)))
            .AddSuggestions(new AnonymousSuggestionSource(suggestionsSource ?? throw Exceptions.BuildArgumentNull(nameof(suggestionsSource)))));
 }
Example #7
0
 /// <inheritdoc/>
 /// <exception cref="ArgumentNullException"><paramref name="item"/> is <see langword="null"/>.</exception>
 protected override void SetItem(int index, ISuggestionSource item)
 {
     base.SetItem(index, item ?? throw Exceptions.BuildArgumentNull(nameof(item)));
 }
Example #8
0
 /// <summary>
 ///     Sets the <see cref="ArgumentBuilder{T}.Name"/> in the argument builder.
 /// </summary>
 /// <typeparam name="T">Type of the argument.</typeparam>
 /// <param name="builder">Source builder.</param>
 /// <param name="name">Name of the argument. It cannot be <see langword="null"/> or whitespace-only.</param>
 /// <returns><paramref name="builder"/>, to allow chaining.</returns>
 /// <exception cref="ArgumentException">The name of the argument is <see langword="null"/> or composed of only whitespaces.</exception>
 /// <exception cref="ArgumentNullException"><paramref name="builder"/> is <see langword="null"/>.</exception>
 public static ArgumentBuilder <T> SetName <T>(this ArgumentBuilder <T> builder, string name)
 {
     (builder ?? throw Exceptions.BuildArgumentNull(nameof(builder)))
     .Name = Validations.IsValidArgumentName(name) ? name : throw Exceptions.BuildArgumentInvalidArgumentName(nameof(name));
     return(builder);
 }
Example #9
0
 /// <summary>
 ///     Limits the accepted values to legal paths.
 /// </summary>
 /// <typeparam name="T">Type of the argument.</typeparam>
 /// <param name="builder">Source builder.</param>
 /// <returns><paramref name="builder"/>, to allow chaining.</returns>
 /// <exception cref="ArgumentNullException"><paramref name="builder"/> is <see langword="null"/>.</exception>
 public static ArgumentBuilder <T> LegalFilePathsOnly <T>(this ArgumentBuilder <T> builder)
 {
     return((builder ?? throw Exceptions.BuildArgumentNull(nameof(builder)))
            .AddBuildConfiguration(argument => argument.LegalFilePathsOnly()));
 }
Example #10
0
 /// <summary>
 ///     Limits the accepted values to existing <see cref="FileSystemInfo"/>.
 /// </summary>
 /// <param name="builder">Source builder.</param>
 /// <returns><paramref name="builder"/>, to allow chaining.</returns>
 /// <exception cref="ArgumentNullException"><paramref name="builder"/> is <see langword="null"/>.</exception>
 public static ArgumentBuilder <FileSystemInfo> ExistingOnly(this ArgumentBuilder <FileSystemInfo> builder)
 {
     return((builder ?? throw Exceptions.BuildArgumentNull(nameof(builder)))
            .AddBuildConfiguration(argument => ((Argument <FileSystemInfo>)argument).ExistingOnly()));
 }
Example #11
0
 /// <summary>
 ///     Limits the accepted values to existing <see cref="FileSystemInfo"/>.
 /// </summary>
 /// <typeparam name="T">Type of the argument.</typeparam>
 /// <param name="builder">Source builder.</param>
 /// <returns><paramref name="builder"/>, to allow chaining.</returns>
 /// <exception cref="ArgumentNullException"><paramref name="builder"/> is <see langword="null"/>.</exception>
 public static ArgumentBuilder <T> ExistingOnly <T>(this ArgumentBuilder <T> builder)
     where T : IEnumerable <FileSystemInfo>
 {
     return((builder ?? throw Exceptions.BuildArgumentNull(nameof(builder)))
            .AddBuildConfiguration(argument => ((Argument <T>)argument).ExistingOnly()));
 }
Example #12
0
 /// <summary>
 ///     Limits the accepted values for the argument to the ones in the provided collection.
 /// </summary>
 /// <typeparam name="T">Type of the argument.</typeparam>
 /// <param name="builder">Source builder.</param>
 /// <param name="values">Values to accept.</param>
 /// <returns><paramref name="builder"/>, to allow chaining.</returns>
 /// <exception cref="ArgumentNullException"><paramref name="builder"/> is <see langword="null"/>.</exception>
 public static ArgumentBuilder <T> LimitTo <T>(this ArgumentBuilder <T> builder, IEnumerable <string> values)
 {
     return((builder ?? throw Exceptions.BuildArgumentNull(nameof(builder)))
            .AddBuildConfiguration(argument => argument.FromAmong((values ?? Enumerable.Empty <string>()).ToArray())));
 }
Example #13
0
 public static ArgumentBuilder <T> AddBuildConfiguration <T>(this ArgumentBuilder <T> builder, Action <Argument> configuration)
 {
     (builder ?? throw Exceptions.BuildArgumentNull(nameof(builder)))
     .BuildConfigurations.Add(configuration ?? throw Exceptions.BuildArgumentNull(nameof(configuration)));
     return(builder);
 }
Example #14
0
 public static ArgumentBuilder <T> AddValidator <T>(this ArgumentBuilder <T> builder, ValidateSymbol <ArgumentResult> validator)
 {
     (builder ?? throw Exceptions.BuildArgumentNull(nameof(builder)))
     .Validators.Add(validator ?? throw Exceptions.BuildArgumentNull(nameof(validator)));
     return(builder);
 }
Example #15
0
 /// <summary>
 ///     Sets whether the option will be hidden in the command help.
 /// </summary>
 /// <typeparam name="T">Type of the option.</typeparam>
 /// <param name="builder">Source builder.</param>
 /// <param name="value"><see langword="true"/> if the option will be hidden in the command help; <see langword="false"/> otherwise. The default is <see langword="true"/>.</param>
 /// <returns><paramref name="builder"/>, to allow chaining.</returns>
 /// <exception cref="ArgumentNullException"><paramref name="builder"/> is <see langword="null"/>.</exception>
 public static OptionBuilder <T> Hide <T>(this OptionBuilder <T> builder, bool value = true)
 {
     (builder ?? throw Exceptions.BuildArgumentNull(nameof(builder)))
     .IsHidden = value;
     return(builder);
 }
Example #16
0
 /// <summary>
 ///     Sets the <see cref="ArgumentBuilder{T}.Description"/> in the argument builder.
 /// </summary>
 /// <typeparam name="T">Type of the argument.</typeparam>
 /// <param name="builder">Source builder.</param>
 /// <param name="description">Description of the argument.</param>
 /// <returns><paramref name="builder"/>, to allow chaining.</returns>
 /// <exception cref="ArgumentNullException"><paramref name="builder"/> is <see langword="null"/>.</exception>
 public static ArgumentBuilder <T> SetDescription <T>(this ArgumentBuilder <T> builder, string?description)
 {
     (builder ?? throw Exceptions.BuildArgumentNull(nameof(builder)))
     .Description = description;
     return(builder);
 }
Example #17
0
 public static OptionBuilder <T> AddSuggestions <T>(this OptionBuilder <T> builder, ISuggestionSource suggestionSource)
 {
     (builder ?? throw Exceptions.BuildArgumentNull(nameof(builder)))
     .Suggestions.Add(suggestionSource ?? throw Exceptions.BuildArgumentNull(nameof(suggestionSource)));
     return(builder);
 }
Example #18
0
 /// <inheritdoc/>
 protected override void InsertItem(int index, ValidateSymbol <OptionResult> item)
 {
     base.InsertItem(index, item ?? throw Exceptions.BuildArgumentNull(nameof(item)));
 }