Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,17 @@ System.CommandLine
public System.Boolean HasDefaultValue { get; }
public System.String HelpName { get; set; }
public System.Type ValueType { get; }
public Argument AcceptLegalFileNamesOnly()
public Argument AcceptLegalFilePathsOnly()
public Argument AcceptOnlyFromAmong(System.String[] values)
public Argument AddCompletions(System.String[] completions)
public Argument AddCompletions(System.Func<System.CommandLine.Completions.CompletionContext,System.Collections.Generic.IEnumerable<System.String>> completionsDelegate)
public Argument AddCompletions(System.Func<System.CommandLine.Completions.CompletionContext,System.Collections.Generic.IEnumerable<System.CommandLine.Completions.CompletionItem>> completionsDelegate)
public System.Void AddValidator(System.Action<System.CommandLine.Parsing.ArgumentResult> validate)
public System.Collections.Generic.IEnumerable<System.CommandLine.Completions.CompletionItem> GetCompletions(System.CommandLine.Completions.CompletionContext context)
public System.Object GetDefaultValue()
public ParseResult Parse(System.String commandLine)
public ParseResult Parse(System.String[] args)
public System.Void SetDefaultValue(System.Object value)
public System.Void SetDefaultValueFactory(System.Func<System.Object> defaultValueFactory)
public System.Void SetDefaultValueFactory(System.Func<System.CommandLine.Parsing.ArgumentResult,System.Object> defaultValueFactory)
Expand All @@ -32,19 +40,11 @@ System.CommandLine
public System.Boolean Equals(ArgumentArity other)
public System.Boolean Equals(System.Object obj)
public System.Int32 GetHashCode()
public static class ArgumentExtensions
public static TArgument AddCompletions<TArgument>(this TArgument argument, System.String[] values)
public static TArgument AddCompletions<TArgument>(this TArgument argument, System.Func<System.CommandLine.Completions.CompletionContext,System.Collections.Generic.IEnumerable<System.String>> complete)
public static TArgument AddCompletions<TArgument>(this TArgument argument, System.Func<System.CommandLine.Completions.CompletionContext,System.Collections.Generic.IEnumerable<System.CommandLine.Completions.CompletionItem>> complete)
public static Argument<System.IO.FileInfo> ExistingOnly(this Argument<System.IO.FileInfo> argument)
public static Argument<System.IO.DirectoryInfo> ExistingOnly(this Argument<System.IO.DirectoryInfo> argument)
public static Argument<System.IO.FileSystemInfo> ExistingOnly(this Argument<System.IO.FileSystemInfo> argument)
public static Argument<T> ExistingOnly<T>(this Argument<T> argument)
public static TArgument FromAmong<TArgument>(this TArgument argument, System.String[] values)
public static TArgument LegalFileNamesOnly<TArgument>(this TArgument argument)
public static TArgument LegalFilePathsOnly<TArgument>(this TArgument argument)
public static ParseResult Parse(this Argument argument, System.String commandLine)
public static ParseResult Parse(this Argument argument, System.String[] args)
public static class ArgumentValidation
public static Argument<System.IO.FileInfo> AcceptExistingOnly(this Argument<System.IO.FileInfo> argument)
public static Argument<System.IO.DirectoryInfo> AcceptExistingOnly(this Argument<System.IO.DirectoryInfo> argument)
public static Argument<System.IO.FileSystemInfo> AcceptExistingOnly(this Argument<System.IO.FileSystemInfo> argument)
public static Argument<T> AcceptExistingOnly<T>(this Argument<T> argument)
public class Command : IdentifierSymbol, System.Collections.Generic.IEnumerable<Symbol>, System.Collections.IEnumerable
.ctor(System.String name, System.String description = null)
public System.Collections.Generic.IReadOnlyList<Argument> Arguments { get; }
Expand Down Expand Up @@ -109,7 +109,7 @@ System.CommandLine
.ctor()
.ctor(System.String message, System.Exception innerException)
public static class CompletionSourceExtensions
public static System.Void Add(this System.Collections.Generic.ICollection<System.Func<System.CommandLine.Completions.CompletionContext,System.Collections.Generic.IEnumerable<System.CommandLine.Completions.CompletionItem>>> completionSources, System.Func<System.CommandLine.Completions.CompletionContext,System.Collections.Generic.IEnumerable<System.String>> complete)
public static System.Void Add(this System.Collections.Generic.ICollection<System.Func<System.CommandLine.Completions.CompletionContext,System.Collections.Generic.IEnumerable<System.CommandLine.Completions.CompletionItem>>> completionSources, System.Func<System.CommandLine.Completions.CompletionContext,System.Collections.Generic.IEnumerable<System.String>> completionsDelegate)
public static System.Void Add(this System.Collections.Generic.ICollection<System.Func<System.CommandLine.Completions.CompletionContext,System.Collections.Generic.IEnumerable<System.CommandLine.Completions.CompletionItem>>> completionSources, System.String[] completions)
public static class ConsoleExtensions
public static System.Void Write(this IConsole console, System.String value)
Expand Down Expand Up @@ -193,9 +193,17 @@ System.CommandLine
public ArgumentArity Arity { get; set; }
public System.Boolean IsRequired { get; set; }
public System.Type ValueType { get; }
public Option AcceptLegalFileNamesOnly()
public Option AcceptLegalFilePathsOnly()
public Option AcceptOnlyFromAmong(System.String[] values)
public Option AddCompletions(System.String[] completions)
public Option AddCompletions(System.Func<System.CommandLine.Completions.CompletionContext,System.Collections.Generic.IEnumerable<System.String>> completionsDelegate)
public Option AddCompletions(System.Func<System.CommandLine.Completions.CompletionContext,System.Collections.Generic.IEnumerable<System.CommandLine.Completions.CompletionItem>> completionsDelegate)
public System.Void AddValidator(System.Action<System.CommandLine.Parsing.OptionResult> validate)
public System.Collections.Generic.IEnumerable<System.CommandLine.Completions.CompletionItem> GetCompletions(System.CommandLine.Completions.CompletionContext context)
public System.Boolean HasAliasIgnoringPrefix(System.String alias)
public ParseResult Parse(System.String commandLine)
public ParseResult Parse(System.String[] args)
public System.Void SetDefaultValue(System.Object value)
public System.Void SetDefaultValueFactory(System.Func<System.Object> defaultValueFactory)
public class Option<T> : Option, IValueDescriptor<T>, System.CommandLine.Binding.IValueDescriptor
Expand All @@ -205,19 +213,11 @@ System.CommandLine
.ctor(System.String[] aliases, Func<System.CommandLine.Parsing.ArgumentResult,T> parseArgument, System.Boolean isDefault = False, System.String description = null)
.ctor(System.String name, Func<T> defaultValueFactory, System.String description = null)
.ctor(System.String[] aliases, Func<T> defaultValueFactory, System.String description = null)
public static class OptionExtensions
public static TOption AddCompletions<TOption>(this TOption option, System.String[] values)
public static TOption AddCompletions<TOption>(this TOption option, System.Func<System.CommandLine.Completions.CompletionContext,System.Collections.Generic.IEnumerable<System.String>> complete)
public static TOption AddCompletions<TOption>(this TOption option, System.Func<System.CommandLine.Completions.CompletionContext,System.Collections.Generic.IEnumerable<System.CommandLine.Completions.CompletionItem>> complete)
public static Option<System.IO.FileInfo> ExistingOnly(this Option<System.IO.FileInfo> option)
public static Option<System.IO.DirectoryInfo> ExistingOnly(this Option<System.IO.DirectoryInfo> option)
public static Option<System.IO.FileSystemInfo> ExistingOnly(this Option<System.IO.FileSystemInfo> option)
public static Option<T> ExistingOnly<T>(this Option<T> option)
public static TOption FromAmong<TOption>(this TOption option, System.String[] values)
public static TOption LegalFileNamesOnly<TOption>(this TOption option)
public static TOption LegalFilePathsOnly<TOption>(this TOption option)
public static ParseResult Parse(this Option option, System.String commandLine)
public static ParseResult Parse(this Option option, System.String[] args)
public static class OptionValidation
public static Option<System.IO.FileInfo> AcceptExistingOnly(this Option<System.IO.FileInfo> option)
public static Option<System.IO.DirectoryInfo> AcceptExistingOnly(this Option<System.IO.DirectoryInfo> option)
public static Option<System.IO.FileSystemInfo> AcceptExistingOnly(this Option<System.IO.FileSystemInfo> option)
public static Option<T> AcceptExistingOnly<T>(this Option<T> option)
public class ParseResult
public System.CommandLine.Parsing.CommandResult CommandResult { get; }
public System.Collections.Generic.IReadOnlyDictionary<System.String,System.Collections.Generic.IReadOnlyList<System.String>> Directives { get; }
Expand Down
12 changes: 9 additions & 3 deletions src/System.CommandLine.Suggest/SuggestionDispatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,15 @@ public SuggestionDispatcher(ISuggestionRegistration suggestionRegistration, ISug

private Command GetCommand { get; }

private Option<FileInfo> ExecutableOption { get; } =
new Option<FileInfo>(new[] { "-e", "--executable" }, "The executable to call for suggestions")
.LegalFilePathsOnly();
private Option<FileInfo> ExecutableOption { get; } = GetExecutableOption();

private static Option<FileInfo> GetExecutableOption()
{
var option = new Option<FileInfo>(new[] { "-e", "--executable" }, "The executable to call for suggestions");
option.AcceptLegalFilePathsOnly();

return option;
}

private Command ListCommand { get; }

Expand Down
2 changes: 1 addition & 1 deletion src/System.CommandLine.Tests/ArgumentTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -769,7 +769,7 @@ public void OnlyTake_can_pass_on_all_tokens_from_a_single_arity_argument_to_anot
public void Argument_of_enum_can_limit_enum_members_as_valid_values()
{
var argument = new Argument<ConsoleColor>()
.FromAmong(ConsoleColor.Red.ToString(), ConsoleColor.Green.ToString());
.AcceptOnlyFromAmong(ConsoleColor.Red.ToString(), ConsoleColor.Green.ToString());
Command command = new("set-color")
{
argument
Expand Down
4 changes: 2 additions & 2 deletions src/System.CommandLine.Tests/CompletionContextTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public void When_position_is_greater_than_input_length_in_a_string_command_line_
var command = new Command("the-command")
{
new Argument<string>(),
new Option<string>("--option1").FromAmong("apple", "banana", "cherry", "durian"),
new Option<string>("--option1").AcceptOnlyFromAmong("apple", "banana", "cherry", "durian"),
new Option<string>("--option2")
};

Expand Down Expand Up @@ -178,7 +178,7 @@ public void When_position_is_unspecified_in_array_command_line_and_final_token_m
{
var command = new Command("the-command")
{
new Option<string>("--option1").FromAmong("apple", "banana", "cherry", "durian"),
new Option<string>("--option1").AcceptOnlyFromAmong("apple", "banana", "cherry", "durian"),
new Option<string>("--option2"),
new Argument<string>()
};
Expand Down
40 changes: 20 additions & 20 deletions src/System.CommandLine.Tests/CompletionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -438,8 +438,8 @@ public void Parser_options_can_supply_context_sensitive_matches()
{
var parser = new RootCommand
{
new Option<string>("--bread").FromAmong("wheat", "sourdough", "rye"),
new Option<string>("--cheese").FromAmong("provolone", "cheddar", "cream cheese")
new Option<string>("--bread").AcceptOnlyFromAmong("wheat", "sourdough", "rye"),
new Option<string>("--cheese").AcceptOnlyFromAmong("provolone", "cheddar", "cream cheese")
};

var commandLine = "--bread";
Expand Down Expand Up @@ -543,8 +543,8 @@ public void Argument_completions_can_be_based_on_the_proximate_option()
var parser = new Parser(
new Command("outer")
{
new Option<string>("--one").FromAmong("one-a", "one-b"),
new Option<string>("--two").FromAmong("two-a", "two-b")
new Option<string>("--one").AcceptOnlyFromAmong("one-a", "one-b"),
new Option<string>("--two").AcceptOnlyFromAmong("two-a", "two-b")
});

var commandLine = "outer --two";
Expand Down Expand Up @@ -642,11 +642,11 @@ public void When_caller_does_the_tokenizing_then_argument_completions_are_based_
var command = new Command("outer")
{
new Option<string>("one")
.FromAmong("one-a", "one-b", "one-c"),
.AcceptOnlyFromAmong("one-a", "one-b", "one-c"),
new Option<string>("two")
.FromAmong("two-a", "two-b", "two-c"),
.AcceptOnlyFromAmong("two-a", "two-b", "two-c"),
new Option<string>("three")
.FromAmong("three-a", "three-b", "three-c")
.AcceptOnlyFromAmong("three-a", "three-b", "three-c")
};

var parser = new CommandLineBuilder(new RootCommand
Expand All @@ -669,11 +669,11 @@ public void When_parsing_from_array_then_argument_completions_are_based_on_the_p
var command = new Command("outer")
{
new Option<string>("one")
.FromAmong("one-a", "one-b", "one-c"),
.AcceptOnlyFromAmong("one-a", "one-b", "one-c"),
new Option<string>("two")
.FromAmong("two-a", "two-b", "two-c"),
.AcceptOnlyFromAmong("two-a", "two-b", "two-c"),
new Option<string>("three")
.FromAmong("three-a", "three-b", "three-c")
.AcceptOnlyFromAmong("three-a", "three-b", "three-c")
};

var result = command.Parse("outer two b");
Expand All @@ -691,15 +691,15 @@ public void When_parsing_from_text_then_argument_completions_are_based_on_the_pr
{
new Command("one")
{
new Argument<string>().FromAmong("one-a", "one-b", "one-c")
new Argument<string>().AcceptOnlyFromAmong("one-a", "one-b", "one-c")
},
new Command("two")
{
new Argument<string>().FromAmong("two-a", "two-b", "two-c")
new Argument<string>().AcceptOnlyFromAmong("two-a", "two-b", "two-c")
},
new Command("three")
{
new Argument<string>().FromAmong("three-a", "three-b", "three-c")
new Argument<string>().AcceptOnlyFromAmong("three-a", "three-b", "three-c")
}
};

Expand All @@ -718,15 +718,15 @@ public void When_parsing_from_array_then_argument_completions_are_based_on_the_p
{
new Command("one")
{
new Argument<string>().FromAmong("one-a", "one-b", "one-c")
new Argument<string>().AcceptOnlyFromAmong("one-a", "one-b", "one-c")
},
new Command("two")
{
new Argument<string>().FromAmong("two-a", "two-b", "two-c")
new Argument<string>().AcceptOnlyFromAmong("two-a", "two-b", "two-c")
},
new Command("three")
{
new Argument<string>().FromAmong("three-a", "three-b", "three-c")
new Argument<string>().AcceptOnlyFromAmong("three-a", "three-b", "three-c")
}
};

Expand All @@ -743,8 +743,8 @@ public void When_parsing_from_text_if_the_proximate_option_is_completed_then_com
{
var command = new RootCommand
{
new Option<string>("--framework").FromAmong("net7.0"),
new Option<string>("--language").FromAmong("C#"),
new Option<string>("--framework").AcceptOnlyFromAmong("net7.0"),
new Option<string>("--language").AcceptOnlyFromAmong("C#"),
new Option<string>("--langVersion")
};
var parser = new CommandLineBuilder(command).Build();
Expand All @@ -760,8 +760,8 @@ public void When_parsing_from_array_if_the_proximate_option_is_completed_then_co
{
var command = new RootCommand
{
new Option<string>("--framework").FromAmong("net7.0"),
new Option<string>("--language").FromAmong("C#"),
new Option<string>("--framework").AcceptOnlyFromAmong("net7.0"),
new Option<string>("--language").AcceptOnlyFromAmong("C#"),
new Option<string>("--langVersion")
};
var parser = new CommandLineBuilder(command).Build();
Expand Down
2 changes: 1 addition & 1 deletion src/System.CommandLine.Tests/OptionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ public void Option_of_boolean_defaults_to_false_when_not_specified()
public void Option_of_enum_can_limit_enum_members_as_valid_values()
{
var option = new Option<ConsoleColor>("--color")
.FromAmong(ConsoleColor.Red.ToString(), ConsoleColor.Green.ToString());
.AcceptOnlyFromAmong(ConsoleColor.Red.ToString(), ConsoleColor.Green.ToString());

var result = option.Parse("--color Fuschia");

Expand Down
2 changes: 1 addition & 1 deletion src/System.CommandLine.Tests/ParseDiagramTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public void Parse_result_diagram_displays_unmatched_tokens()
{
var command = new Command("command")
{
new Option<string>("-x").FromAmong("arg1", "arg2", "arg3")
new Option<string>("-x").AcceptOnlyFromAmong("arg1", "arg2", "arg3")
};

var result = command.Parse("command -x ar");
Expand Down
2 changes: 1 addition & 1 deletion src/System.CommandLine.Tests/ParserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ public void Parser_root_Options_can_be_specified_multiple_times_and_their_argume
public void Options_can_be_specified_multiple_times_and_their_arguments_are_collated()
{
var animalsOption = new Option<string[]>(new[] { "-a", "--animals" })
.FromAmong("dog", "cat", "sheep");
.AcceptOnlyFromAmong("dog", "cat", "sheep");
var vegetablesOption = new Option<string[]>(new[] { "-v", "--vegetables" });
var parser = new Parser(
new Command("the-command") {
Expand Down
Loading