Skip to content

Commit 8b66431

Browse files
jozkeejonsequitur
authored andcommitted
Rename getDefaultValue to defaultValueFactory in Argument and Option
1 parent 73e908c commit 8b66431

File tree

12 files changed

+49
-49
lines changed

12 files changed

+49
-49
lines changed

src/System.CommandLine.ApiCompatibility.Tests/ApiCompatibilityApprovalTests.System_CommandLine_api_is_not_changed.approved.txt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ System.CommandLine
99
public System.Collections.Generic.IEnumerable<System.CommandLine.Completions.CompletionItem> GetCompletions(System.CommandLine.Completions.CompletionContext context)
1010
public System.Object GetDefaultValue()
1111
public System.Void SetDefaultValue(System.Object value)
12-
public System.Void SetDefaultValueFactory(System.Func<System.Object> getDefaultValue)
13-
public System.Void SetDefaultValueFactory(System.Func<System.CommandLine.Parsing.ArgumentResult,System.Object> getDefaultValue)
12+
public System.Void SetDefaultValueFactory(System.Func<System.Object> defaultValueFactory)
13+
public System.Void SetDefaultValueFactory(System.Func<System.CommandLine.Parsing.ArgumentResult,System.Object> defaultValueFactory)
1414
public System.String ToString()
1515
public class Argument<T> : Argument, IValueDescriptor<T>, System.CommandLine.Binding.IValueDescriptor, System.CommandLine.Completions.ICompletionSource
1616
.ctor()
1717
.ctor(System.String name, System.String description = null)
18-
.ctor(System.String name, Func<T> getDefaultValue, System.String description = null)
19-
.ctor(Func<T> getDefaultValue)
18+
.ctor(System.String name, Func<T> defaultValueFactory, System.String description = null)
19+
.ctor(Func<T> defaultValueFactory)
2020
.ctor(System.String name, Func<System.CommandLine.Parsing.ArgumentResult,T> parse, System.Boolean isDefault = False, System.String description = null)
2121
.ctor(Func<System.CommandLine.Parsing.ArgumentResult,T> parse, System.Boolean isDefault = False)
2222
public System.Type ValueType { get; }
@@ -198,14 +198,14 @@ System.CommandLine
198198
public System.Collections.Generic.IEnumerable<System.CommandLine.Completions.CompletionItem> GetCompletions(System.CommandLine.Completions.CompletionContext context)
199199
public System.Boolean HasAliasIgnoringPrefix(System.String alias)
200200
public System.Void SetDefaultValue(System.Object value)
201-
public System.Void SetDefaultValueFactory(System.Func<System.Object> getDefaultValue)
201+
public System.Void SetDefaultValueFactory(System.Func<System.Object> defaultValueFactory)
202202
public class Option<T> : Option, IValueDescriptor<T>, System.CommandLine.Binding.IValueDescriptor, System.CommandLine.Completions.ICompletionSource
203203
.ctor(System.String name, System.String description = null)
204204
.ctor(System.String[] aliases, System.String description = null)
205205
.ctor(System.String name, Func<System.CommandLine.Parsing.ArgumentResult,T> parseArgument, System.Boolean isDefault = False, System.String description = null)
206206
.ctor(System.String[] aliases, Func<System.CommandLine.Parsing.ArgumentResult,T> parseArgument, System.Boolean isDefault = False, System.String description = null)
207-
.ctor(System.String name, Func<T> getDefaultValue, System.String description = null)
208-
.ctor(System.String[] aliases, Func<T> getDefaultValue, System.String description = null)
207+
.ctor(System.String name, Func<T> defaultValueFactory, System.String description = null)
208+
.ctor(System.String[] aliases, Func<T> defaultValueFactory, System.String description = null)
209209
public ArgumentArity Arity { get; set; }
210210
public static class OptionExtensions
211211
public static TOption AddCompletions<TOption>(this TOption option, System.String[] values)

src/System.CommandLine.Suggest/SuggestionDispatcher.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public SuggestionDispatcher(ISuggestionRegistration suggestionRegistration, ISug
9797

9898
private Option<int> PositionOption { get; } = new(new[] { "-p", "--position" },
9999
description: "The current character position on the command line",
100-
getDefaultValue: () => short.MaxValue);
100+
defaultValueFactory: () => short.MaxValue);
101101

102102
private Command RegisterCommand { get; }
103103

src/System.CommandLine.Tests/CompletionTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ public void When_an_option_has_a_default_value_it_will_still_be_suggested()
189189
{
190190
var parser = new RootCommand
191191
{
192-
new Option<string>("--apple", getDefaultValue: () => "cortland"),
192+
new Option<string>("--apple", defaultValueFactory: () => "cortland"),
193193
new Option<string>("--banana"),
194194
new Option<string>("--cherry")
195195
};

src/System.CommandLine.Tests/Help/HelpBuilderTests.Customization.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ private HelpBuilder GetHelpBuilder(int maxWidth) =>
3535
[Fact]
3636
public void Option_can_customize_default_value()
3737
{
38-
var option = new Option<string>("--the-option", getDefaultValue: () => "not 42");
38+
var option = new Option<string>("--the-option", defaultValueFactory: () => "not 42");
3939
var command = new Command("the-command", "command help")
4040
{
4141
option
@@ -188,7 +188,7 @@ public void Command_arguments_can_customize_first_column_text()
188188
[Fact]
189189
public void Command_arguments_can_customize_second_column_text()
190190
{
191-
var argument = new Argument<string>("some-arg", description: "Default description", getDefaultValue: () => "not 42");
191+
var argument = new Argument<string>("some-arg", description: "Default description", defaultValueFactory: () => "not 42");
192192
var command = new Command("the-command", "command help")
193193
{
194194
argument
@@ -207,7 +207,7 @@ public void Command_arguments_can_customize_second_column_text()
207207
[Fact]
208208
public void Command_arguments_can_customize_default_value()
209209
{
210-
var argument = new Argument<string>("some-arg", getDefaultValue: () => "not 42");
210+
var argument = new Argument<string>("some-arg", defaultValueFactory: () => "not 42");
211211
var command = new Command("the-command", "command help")
212212
{
213213
argument

src/System.CommandLine.Tests/Help/HelpBuilderTests.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -921,7 +921,7 @@ public void Command_arguments_with_default_values_that_are_enumerable_display_pi
921921
var command = new Command("the-command", "command help")
922922
{
923923
new Argument<List<int>>("filter-size",
924-
getDefaultValue: () => new List<int>() { 0, 2, 4 })
924+
defaultValueFactory: () => new List<int>() { 0, 2, 4 })
925925
};
926926

927927
_helpBuilder.Write(command, _console);
@@ -1149,7 +1149,7 @@ public void Options_section_properly_wraps_description_when_long_default_value_i
11491149
var command = new Command("test-command", "Help text for the command")
11501150
{
11511151
new Option<string>("-x", "Option with a short description"),
1152-
new Option<string>(new[] { "-a", "--aaa" }, description: longOptionText, getDefaultValue: () => "the quick brown fox jumps over the lazy dog"),
1152+
new Option<string>(new[] { "-a", "--aaa" }, description: longOptionText, defaultValueFactory: () => "the quick brown fox jumps over the lazy dog"),
11531153
new Option<string>("-y", "Option with a short description"),
11541154
};
11551155

@@ -1313,7 +1313,7 @@ public void Help_describes_default_value_for_option_with_argument_having_default
13131313
{
13141314
var command = new Command("the-command", "command help")
13151315
{
1316-
new Option<string>(new[] { "-arg"}, getDefaultValue: () => "the-arg-value")
1316+
new Option<string>(new[] { "-arg"}, defaultValueFactory: () => "the-arg-value")
13171317
{
13181318
ArgumentHelpName = "the-arg"
13191319
}
@@ -1335,7 +1335,7 @@ public void Option_arguments_with_default_values_that_are_enumerable_display_pip
13351335
{
13361336
new Option<List<int>>(
13371337
"--filter-size",
1338-
getDefaultValue: () => new List<int> { 0, 2, 4 })
1338+
defaultValueFactory: () => new List<int> { 0, 2, 4 })
13391339
{ }
13401340
};
13411341

@@ -1354,7 +1354,7 @@ public void Option_arguments_with_default_values_that_are_array_display_pipe_del
13541354
{
13551355
new Option<string[]>(
13561356
"--prefixes",
1357-
getDefaultValue: () => new[]{ "^(TODO|BUG)", "^HACK" })
1357+
defaultValueFactory: () => new[]{ "^(TODO|BUG)", "^HACK" })
13581358
{ }
13591359
};
13601360

src/System.CommandLine.Tests/ParserTests.MultipleArguments.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ public void Unsatisfied_subsequent_argument_with_min_arity_0_parses_as_default_v
252252
public void Unsatisfied_subsequent_argument_with_min_arity_1_parses_as_default_value()
253253
{
254254
Argument<string> arg1 = new(name: "arg1");
255-
Argument<string> arg2 = new(name: "arg2", getDefaultValue: () => "the-default");
255+
Argument<string> arg2 = new(name: "arg2", defaultValueFactory: () => "the-default");
256256

257257
var rootCommand = new RootCommand
258258
{

src/System.CommandLine.Tests/ParserTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1556,7 +1556,7 @@ public void A_subcommand_wont_overflow_when_checking_maximum_argument_capacity()
15561556
[InlineData("--exec-prefix=", "")]
15571557
public void Parsed_value_of_empty_string_arg_is_an_empty_string(string arg1, string arg2)
15581558
{
1559-
var option = new Option<string>("--exec-prefix", getDefaultValue: () => "/usr/local");
1559+
var option = new Option<string>("--exec-prefix", defaultValueFactory: () => "/usr/local");
15601560
var rootCommand = new RootCommand
15611561
{
15621562
option

src/System.CommandLine.Tests/VersionOptionTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public async Task When_the_version_option_is_specified_and_there_are_default_arg
9393
{
9494
var rootCommand = new RootCommand
9595
{
96-
new Argument<bool>("x", getDefaultValue: () => true)
96+
new Argument<bool>("x", defaultValueFactory: () => true)
9797
};
9898
rootCommand.SetHandler(() => { });
9999

src/System.CommandLine/Argument.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -144,26 +144,26 @@ public void SetDefaultValue(object? value)
144144
/// <summary>
145145
/// Sets a delegate to invoke when the default value for the argument is required.
146146
/// </summary>
147-
/// <param name="getDefaultValue">The delegate to invoke to return the default value.</param>
148-
/// <exception cref="ArgumentNullException">Thrown when <paramref name="getDefaultValue"/> is null.</exception>
149-
public void SetDefaultValueFactory(Func<object?> getDefaultValue)
147+
/// <param name="defaultValueFactory">The delegate to invoke to return the default value.</param>
148+
/// <exception cref="ArgumentNullException">Thrown when <paramref name="defaultValueFactory"/> is null.</exception>
149+
public void SetDefaultValueFactory(Func<object?> defaultValueFactory)
150150
{
151-
if (getDefaultValue is null)
151+
if (defaultValueFactory is null)
152152
{
153-
throw new ArgumentNullException(nameof(getDefaultValue));
153+
throw new ArgumentNullException(nameof(defaultValueFactory));
154154
}
155155

156-
SetDefaultValueFactory(_ => getDefaultValue());
156+
SetDefaultValueFactory(_ => defaultValueFactory());
157157
}
158158

159159
/// <summary>
160160
/// Sets a delegate to invoke when the default value for the argument is required.
161161
/// </summary>
162-
/// <param name="getDefaultValue">The delegate to invoke to return the default value.</param>
162+
/// <param name="defaultValueFactory">The delegate to invoke to return the default value.</param>
163163
/// <remarks>In this overload, the <see cref="ArgumentResult"/> is provided to the delegate.</remarks>
164-
public void SetDefaultValueFactory(Func<ArgumentResult, object?> getDefaultValue)
164+
public void SetDefaultValueFactory(Func<ArgumentResult, object?> defaultValueFactory)
165165
{
166-
_defaultValueFactory = getDefaultValue ?? throw new ArgumentNullException(nameof(getDefaultValue));
166+
_defaultValueFactory = defaultValueFactory ?? throw new ArgumentNullException(nameof(defaultValueFactory));
167167
}
168168

169169
/// <summary>

src/System.CommandLine/Argument{T}.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,35 +29,35 @@ public Argument(
2929
/// Initializes a new instance of the Argument class.
3030
/// </summary>
3131
/// <param name="name">The name of the argument.</param>
32-
/// <param name="getDefaultValue">The delegate to invoke to return the default value.</param>
32+
/// <param name="defaultValueFactory">The delegate to invoke to return the default value.</param>
3333
/// <param name="description">The description of the argument, shown in help.</param>
34-
/// <exception cref="ArgumentNullException">Thrown when <paramref name="getDefaultValue"/> is null.</exception>
34+
/// <exception cref="ArgumentNullException">Thrown when <paramref name="defaultValueFactory"/> is null.</exception>
3535
public Argument(
3636
string name,
37-
Func<T> getDefaultValue,
37+
Func<T> defaultValueFactory,
3838
string? description = null) : this(name, description)
3939
{
40-
if (getDefaultValue is null)
40+
if (defaultValueFactory is null)
4141
{
42-
throw new ArgumentNullException(nameof(getDefaultValue));
42+
throw new ArgumentNullException(nameof(defaultValueFactory));
4343
}
4444

45-
SetDefaultValueFactory(() => getDefaultValue());
45+
SetDefaultValueFactory(() => defaultValueFactory());
4646
}
4747

4848
/// <summary>
4949
/// Initializes a new instance of the Argument class.
5050
/// </summary>
51-
/// <param name="getDefaultValue">The delegate to invoke to return the default value.</param>
52-
/// <exception cref="ArgumentNullException">Thrown when <paramref name="getDefaultValue"/> is null.</exception>
53-
public Argument(Func<T> getDefaultValue) : this()
51+
/// <param name="defaultValueFactory">The delegate to invoke to return the default value.</param>
52+
/// <exception cref="ArgumentNullException">Thrown when <paramref name="defaultValueFactory"/> is null.</exception>
53+
public Argument(Func<T> defaultValueFactory) : this()
5454
{
55-
if (getDefaultValue is null)
55+
if (defaultValueFactory is null)
5656
{
57-
throw new ArgumentNullException(nameof(getDefaultValue));
57+
throw new ArgumentNullException(nameof(defaultValueFactory));
5858
}
5959

60-
SetDefaultValueFactory(() => getDefaultValue());
60+
SetDefaultValueFactory(() => defaultValueFactory());
6161
}
6262

6363
/// <summary>

0 commit comments

Comments
 (0)