diff --git a/src/System.CommandLine.ApiCompatibility.Tests/ApiCompatibilityApprovalTests.System_CommandLine_api_is_not_changed.approved.txt b/src/System.CommandLine.ApiCompatibility.Tests/ApiCompatibilityApprovalTests.System_CommandLine_api_is_not_changed.approved.txt index f325f26377..73a3e868cc 100644 --- a/src/System.CommandLine.ApiCompatibility.Tests/ApiCompatibilityApprovalTests.System_CommandLine_api_is_not_changed.approved.txt +++ b/src/System.CommandLine.ApiCompatibility.Tests/ApiCompatibilityApprovalTests.System_CommandLine_api_is_not_changed.approved.txt @@ -9,14 +9,14 @@ System.CommandLine public System.Collections.Generic.IEnumerable GetCompletions(System.CommandLine.Completions.CompletionContext context) public System.Object GetDefaultValue() public System.Void SetDefaultValue(System.Object value) - public System.Void SetDefaultValueFactory(System.Func getDefaultValue) - public System.Void SetDefaultValueFactory(System.Func getDefaultValue) + public System.Void SetDefaultValueFactory(System.Func defaultValueFactory) + public System.Void SetDefaultValueFactory(System.Func defaultValueFactory) public System.String ToString() public class Argument : Argument, IValueDescriptor, System.CommandLine.Binding.IValueDescriptor, System.CommandLine.Completions.ICompletionSource .ctor() .ctor(System.String name, System.String description = null) - .ctor(System.String name, Func getDefaultValue, System.String description = null) - .ctor(Func getDefaultValue) + .ctor(System.String name, Func defaultValueFactory, System.String description = null) + .ctor(Func defaultValueFactory) .ctor(System.String name, Func parse, System.Boolean isDefault = False, System.String description = null) .ctor(Func parse, System.Boolean isDefault = False) public System.Type ValueType { get; } @@ -198,14 +198,14 @@ System.CommandLine public System.Collections.Generic.IEnumerable GetCompletions(System.CommandLine.Completions.CompletionContext context) public System.Boolean HasAliasIgnoringPrefix(System.String alias) public System.Void SetDefaultValue(System.Object value) - public System.Void SetDefaultValueFactory(System.Func getDefaultValue) + public System.Void SetDefaultValueFactory(System.Func defaultValueFactory) public class Option : Option, IValueDescriptor, System.CommandLine.Binding.IValueDescriptor, System.CommandLine.Completions.ICompletionSource .ctor(System.String name, System.String description = null) .ctor(System.String[] aliases, System.String description = null) .ctor(System.String name, Func parseArgument, System.Boolean isDefault = False, System.String description = null) .ctor(System.String[] aliases, Func parseArgument, System.Boolean isDefault = False, System.String description = null) - .ctor(System.String name, Func getDefaultValue, System.String description = null) - .ctor(System.String[] aliases, Func getDefaultValue, System.String description = null) + .ctor(System.String name, Func defaultValueFactory, System.String description = null) + .ctor(System.String[] aliases, Func defaultValueFactory, System.String description = null) public ArgumentArity Arity { get; set; } public static class OptionExtensions public static TOption AddCompletions(this TOption option, System.String[] values) diff --git a/src/System.CommandLine.Suggest/SuggestionDispatcher.cs b/src/System.CommandLine.Suggest/SuggestionDispatcher.cs index ef916dbe0d..0a350926d3 100644 --- a/src/System.CommandLine.Suggest/SuggestionDispatcher.cs +++ b/src/System.CommandLine.Suggest/SuggestionDispatcher.cs @@ -97,7 +97,7 @@ public SuggestionDispatcher(ISuggestionRegistration suggestionRegistration, ISug private Option PositionOption { get; } = new(new[] { "-p", "--position" }, description: "The current character position on the command line", - getDefaultValue: () => short.MaxValue); + defaultValueFactory: () => short.MaxValue); private Command RegisterCommand { get; } diff --git a/src/System.CommandLine.Tests/CompletionTests.cs b/src/System.CommandLine.Tests/CompletionTests.cs index ddb31b8c33..67e59ea177 100644 --- a/src/System.CommandLine.Tests/CompletionTests.cs +++ b/src/System.CommandLine.Tests/CompletionTests.cs @@ -189,7 +189,7 @@ public void When_an_option_has_a_default_value_it_will_still_be_suggested() { var parser = new RootCommand { - new Option("--apple", getDefaultValue: () => "cortland"), + new Option("--apple", defaultValueFactory: () => "cortland"), new Option("--banana"), new Option("--cherry") }; diff --git a/src/System.CommandLine.Tests/Help/HelpBuilderTests.Customization.cs b/src/System.CommandLine.Tests/Help/HelpBuilderTests.Customization.cs index 4d72c4513d..edc6e506be 100644 --- a/src/System.CommandLine.Tests/Help/HelpBuilderTests.Customization.cs +++ b/src/System.CommandLine.Tests/Help/HelpBuilderTests.Customization.cs @@ -35,7 +35,7 @@ private HelpBuilder GetHelpBuilder(int maxWidth) => [Fact] public void Option_can_customize_default_value() { - var option = new Option("--the-option", getDefaultValue: () => "not 42"); + var option = new Option("--the-option", defaultValueFactory: () => "not 42"); var command = new Command("the-command", "command help") { option @@ -188,7 +188,7 @@ public void Command_arguments_can_customize_first_column_text() [Fact] public void Command_arguments_can_customize_second_column_text() { - var argument = new Argument("some-arg", description: "Default description", getDefaultValue: () => "not 42"); + var argument = new Argument("some-arg", description: "Default description", defaultValueFactory: () => "not 42"); var command = new Command("the-command", "command help") { argument @@ -207,7 +207,7 @@ public void Command_arguments_can_customize_second_column_text() [Fact] public void Command_arguments_can_customize_default_value() { - var argument = new Argument("some-arg", getDefaultValue: () => "not 42"); + var argument = new Argument("some-arg", defaultValueFactory: () => "not 42"); var command = new Command("the-command", "command help") { argument diff --git a/src/System.CommandLine.Tests/Help/HelpBuilderTests.cs b/src/System.CommandLine.Tests/Help/HelpBuilderTests.cs index dd8914f09a..0c3e5cd5f3 100644 --- a/src/System.CommandLine.Tests/Help/HelpBuilderTests.cs +++ b/src/System.CommandLine.Tests/Help/HelpBuilderTests.cs @@ -921,7 +921,7 @@ public void Command_arguments_with_default_values_that_are_enumerable_display_pi var command = new Command("the-command", "command help") { new Argument>("filter-size", - getDefaultValue: () => new List() { 0, 2, 4 }) + defaultValueFactory: () => new List() { 0, 2, 4 }) }; _helpBuilder.Write(command, _console); @@ -1149,7 +1149,7 @@ public void Options_section_properly_wraps_description_when_long_default_value_i var command = new Command("test-command", "Help text for the command") { new Option("-x", "Option with a short description"), - new Option(new[] { "-a", "--aaa" }, description: longOptionText, getDefaultValue: () => "the quick brown fox jumps over the lazy dog"), + new Option(new[] { "-a", "--aaa" }, description: longOptionText, defaultValueFactory: () => "the quick brown fox jumps over the lazy dog"), new Option("-y", "Option with a short description"), }; @@ -1313,7 +1313,7 @@ public void Help_describes_default_value_for_option_with_argument_having_default { var command = new Command("the-command", "command help") { - new Option(new[] { "-arg"}, getDefaultValue: () => "the-arg-value") + new Option(new[] { "-arg"}, defaultValueFactory: () => "the-arg-value") { ArgumentHelpName = "the-arg" } @@ -1335,7 +1335,7 @@ public void Option_arguments_with_default_values_that_are_enumerable_display_pip { new Option>( "--filter-size", - getDefaultValue: () => new List { 0, 2, 4 }) + defaultValueFactory: () => new List { 0, 2, 4 }) { } }; @@ -1354,7 +1354,7 @@ public void Option_arguments_with_default_values_that_are_array_display_pipe_del { new Option( "--prefixes", - getDefaultValue: () => new[]{ "^(TODO|BUG)", "^HACK" }) + defaultValueFactory: () => new[]{ "^(TODO|BUG)", "^HACK" }) { } }; diff --git a/src/System.CommandLine.Tests/ParserTests.MultipleArguments.cs b/src/System.CommandLine.Tests/ParserTests.MultipleArguments.cs index db83bb6ffd..331f8d6515 100644 --- a/src/System.CommandLine.Tests/ParserTests.MultipleArguments.cs +++ b/src/System.CommandLine.Tests/ParserTests.MultipleArguments.cs @@ -252,7 +252,7 @@ public void Unsatisfied_subsequent_argument_with_min_arity_0_parses_as_default_v public void Unsatisfied_subsequent_argument_with_min_arity_1_parses_as_default_value() { Argument arg1 = new(name: "arg1"); - Argument arg2 = new(name: "arg2", getDefaultValue: () => "the-default"); + Argument arg2 = new(name: "arg2", defaultValueFactory: () => "the-default"); var rootCommand = new RootCommand { diff --git a/src/System.CommandLine.Tests/ParserTests.cs b/src/System.CommandLine.Tests/ParserTests.cs index d91bf3ab97..6878f12328 100644 --- a/src/System.CommandLine.Tests/ParserTests.cs +++ b/src/System.CommandLine.Tests/ParserTests.cs @@ -1556,7 +1556,7 @@ public void A_subcommand_wont_overflow_when_checking_maximum_argument_capacity() [InlineData("--exec-prefix=", "")] public void Parsed_value_of_empty_string_arg_is_an_empty_string(string arg1, string arg2) { - var option = new Option("--exec-prefix", getDefaultValue: () => "/usr/local"); + var option = new Option("--exec-prefix", defaultValueFactory: () => "/usr/local"); var rootCommand = new RootCommand { option diff --git a/src/System.CommandLine.Tests/VersionOptionTests.cs b/src/System.CommandLine.Tests/VersionOptionTests.cs index 83caf7bb86..5d3a5ce7b7 100644 --- a/src/System.CommandLine.Tests/VersionOptionTests.cs +++ b/src/System.CommandLine.Tests/VersionOptionTests.cs @@ -93,7 +93,7 @@ public async Task When_the_version_option_is_specified_and_there_are_default_arg { var rootCommand = new RootCommand { - new Argument("x", getDefaultValue: () => true) + new Argument("x", defaultValueFactory: () => true) }; rootCommand.SetHandler(() => { }); diff --git a/src/System.CommandLine/Argument.cs b/src/System.CommandLine/Argument.cs index a5466ec8eb..e6300bf1bc 100644 --- a/src/System.CommandLine/Argument.cs +++ b/src/System.CommandLine/Argument.cs @@ -144,26 +144,26 @@ public void SetDefaultValue(object? value) /// /// Sets a delegate to invoke when the default value for the argument is required. /// - /// The delegate to invoke to return the default value. - /// Thrown when is null. - public void SetDefaultValueFactory(Func getDefaultValue) + /// The delegate to invoke to return the default value. + /// Thrown when is null. + public void SetDefaultValueFactory(Func defaultValueFactory) { - if (getDefaultValue is null) + if (defaultValueFactory is null) { - throw new ArgumentNullException(nameof(getDefaultValue)); + throw new ArgumentNullException(nameof(defaultValueFactory)); } - SetDefaultValueFactory(_ => getDefaultValue()); + SetDefaultValueFactory(_ => defaultValueFactory()); } /// /// Sets a delegate to invoke when the default value for the argument is required. /// - /// The delegate to invoke to return the default value. + /// The delegate to invoke to return the default value. /// In this overload, the is provided to the delegate. - public void SetDefaultValueFactory(Func getDefaultValue) + public void SetDefaultValueFactory(Func defaultValueFactory) { - _defaultValueFactory = getDefaultValue ?? throw new ArgumentNullException(nameof(getDefaultValue)); + _defaultValueFactory = defaultValueFactory ?? throw new ArgumentNullException(nameof(defaultValueFactory)); } /// diff --git a/src/System.CommandLine/Argument{T}.cs b/src/System.CommandLine/Argument{T}.cs index 51321274c4..ed632e0ce6 100644 --- a/src/System.CommandLine/Argument{T}.cs +++ b/src/System.CommandLine/Argument{T}.cs @@ -29,35 +29,35 @@ public Argument( /// Initializes a new instance of the Argument class. /// /// The name of the argument. - /// The delegate to invoke to return the default value. + /// The delegate to invoke to return the default value. /// The description of the argument, shown in help. - /// Thrown when is null. + /// Thrown when is null. public Argument( string name, - Func getDefaultValue, + Func defaultValueFactory, string? description = null) : this(name, description) { - if (getDefaultValue is null) + if (defaultValueFactory is null) { - throw new ArgumentNullException(nameof(getDefaultValue)); + throw new ArgumentNullException(nameof(defaultValueFactory)); } - SetDefaultValueFactory(() => getDefaultValue()); + SetDefaultValueFactory(() => defaultValueFactory()); } /// /// Initializes a new instance of the Argument class. /// - /// The delegate to invoke to return the default value. - /// Thrown when is null. - public Argument(Func getDefaultValue) : this() + /// The delegate to invoke to return the default value. + /// Thrown when is null. + public Argument(Func defaultValueFactory) : this() { - if (getDefaultValue is null) + if (defaultValueFactory is null) { - throw new ArgumentNullException(nameof(getDefaultValue)); + throw new ArgumentNullException(nameof(defaultValueFactory)); } - SetDefaultValueFactory(() => getDefaultValue()); + SetDefaultValueFactory(() => defaultValueFactory()); } /// diff --git a/src/System.CommandLine/Option.cs b/src/System.CommandLine/Option.cs index 40f09877de..7ff0f39200 100644 --- a/src/System.CommandLine/Option.cs +++ b/src/System.CommandLine/Option.cs @@ -152,10 +152,10 @@ public void SetDefaultValue(object? value) => /// /// Sets a delegate to invoke when the default value for the option is required. /// - /// The delegate to invoke to return the default value. - /// Thrown when is null. - public void SetDefaultValueFactory(Func getDefaultValue) => - Argument.SetDefaultValueFactory(getDefaultValue); + /// The delegate to invoke to return the default value. + /// Thrown when is null. + public void SetDefaultValueFactory(Func defaultValueFactory) => + Argument.SetDefaultValueFactory(defaultValueFactory); /// /// Gets a value that indicates whether multiple argument tokens are allowed for each option identifier token. diff --git a/src/System.CommandLine/Option{T}.cs b/src/System.CommandLine/Option{T}.cs index a67e56e2e5..0a1f182caa 100644 --- a/src/System.CommandLine/Option{T}.cs +++ b/src/System.CommandLine/Option{T}.cs @@ -46,18 +46,18 @@ public Option( /// public Option( string name, - Func getDefaultValue, + Func defaultValueFactory, string? description = null) : base(name, description, - new Argument(getDefaultValue ?? throw new ArgumentNullException(nameof(getDefaultValue)))) + new Argument(defaultValueFactory ?? throw new ArgumentNullException(nameof(defaultValueFactory)))) { } /// public Option( string[] aliases, - Func getDefaultValue, + Func defaultValueFactory, string? description = null) - : base(aliases, description, new Argument(getDefaultValue ?? throw new ArgumentNullException(nameof(getDefaultValue)))) + : base(aliases, description, new Argument(defaultValueFactory ?? throw new ArgumentNullException(nameof(defaultValueFactory)))) { }