You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Made required behaviour for CliArgument and CliOption more sensible
If the decorated property has a default value (set via a property initializer), the argument/option is detected as "not required".
If the decorated property does not have a default value, the argument/option is detected as "required".
If you want to force an argument/option to be required, set this property to `true`. In that case,
the default value for the decorated property will be ignored (if exists).
If you want to force an argument/option to be not required, set this property to `false`.
Copy file name to clipboardExpand all lines: src/DotMake.CommandLine.Shared/Attributes/CliArgumentAttribute.cs
+16-8Lines changed: 16 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,10 @@ namespace DotMake.CommandLine
4
4
{
5
5
/// <summary>
6
6
/// Specifies a class property that represents an argument which is a value that can be passed on the command line to a command or an option.
7
-
/// <para>Note that arguments are required by default, see <see cref="Required"/> property for details.</para>
7
+
/// <para>
8
+
/// Note that an argument is required if the decorated property does not have a default value (set via a property initializer),
9
+
/// see <see cref="Required"/> property for details.
10
+
/// </para>
8
11
/// <para>
9
12
/// <b>Arguments:</b> An argument is a value passed to an option or a command. The following examples show an argument for the <c>verbosity</c> option and an argument for the <c>build</c> command.
10
13
/// <code>
@@ -57,18 +60,23 @@ public class CliArgumentAttribute : Attribute
57
60
58
61
/// <summary>
59
62
/// Gets or sets a value indicating whether the argument is required when its parent command is invoked.
60
-
/// Default is <see langword="true" /> for arguments.
63
+
/// Default is auto-detected.
64
+
/// <para>
65
+
/// If the decorated property has a default value (set via a property initializer), the argument is detected as "not required".
66
+
/// If the decorated property does not have a default value, the argument is detected as "required".
67
+
/// </para>
61
68
/// <para>
62
-
/// When an argument is required and its parent command is invoked without it,
63
-
/// an error message is displayed and the command handler isn't called.
69
+
/// If you want to force an argument to be required, set this property to <see langword="true"/>. In that case,
70
+
/// the default value for the decorated property will be ignored (if exists).
71
+
/// If you want to force an argument to be not required, set this property to <see langword="false"/>.
64
72
/// </para>
65
73
/// <para>
66
-
/// If you want to make a CliArgument optional, set this property to <see langword="false"/> and set a default value
67
-
/// for the decorated property.In that case, the default value for the decorated property will be used when the user
68
-
/// does not specify the argument on the command line.
74
+
/// When an argument is required, the argument has to be specified on the command line and if its parent command is invoked
75
+
/// without it, an error message is displayed and the command handler isn't called.
76
+
/// When an argument is not required, the argument doesn't have to be specified on the command line, the default value provides the argument value.
69
77
/// </para>
70
78
/// </summary>
71
-
publicboolRequired{get;set;}=true;
79
+
publicboolRequired{get;set;}
72
80
73
81
/// <summary>
74
82
/// Gets or sets the arity of the argument. The arity refers to the number of values that can be passed on the command line.
Copy file name to clipboardExpand all lines: src/DotMake.CommandLine.Shared/Attributes/CliOptionAttribute.cs
+15-7Lines changed: 15 additions & 7 deletions
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,10 @@ namespace DotMake.CommandLine
4
4
{
5
5
/// <summary>
6
6
/// Specifies a class property that represents an option which is a named parameter and a value for that parameter, that is used on the command line.
7
-
/// <para>Note that options are not required by default (optional as the name implies), see <see cref="Required"/> property for details.</para>
7
+
/// <para>
8
+
/// Note that an option is required if the decorated property does not have a default value (set via a property initializer),
9
+
/// see <see cref="Required"/> property for details.
10
+
/// </para>
8
11
/// <para>
9
12
/// <b>Options:</b> An option is a named parameter that can be passed to a command. The POSIX convention is to prefix the option name with two hyphens (<c>--</c>).
10
13
/// The following example shows two options:
@@ -75,15 +78,20 @@ public class CliOptionAttribute : Attribute
75
78
76
79
/// <summary>
77
80
/// Gets or sets a value indicating whether the option is required when its parent command is invoked.
78
-
/// Default is <see langword="false" /> for options.
81
+
/// Default is auto-detected.
82
+
/// <para>
83
+
/// If the decorated property has a default value (set via a property initializer), the option is detected as "not required".
84
+
/// If the decorated property does not have a default value, the option is detected as "required".
85
+
/// </para>
79
86
/// <para>
80
-
/// When an option is required and its parent command is invoked without it,
81
-
/// an error message is displayed and the command handler isn't called.
87
+
/// If you want to force an option to be required, set this property to <see langword="true"/>. In that case,
88
+
/// the default value for the decorated property will be ignored (if exists).
89
+
/// If you want to force an option to be not required, set this property to <see langword="false"/>.
82
90
/// </para>
83
91
/// <para>
84
-
/// If you want to make a CliOption required, set this property to <see langword="true"/>. In that case,
85
-
/// the default value for the decorated property will be ignored (if exists) and the user has to specify
86
-
/// the option on the command line.
92
+
/// When an option is required, the option has to be specified on the command line and if its parent command is invoked
93
+
/// without it, an error message is displayed and the command handler isn't called.
94
+
/// When an option is not required, the option doesn't have to be specified on the command line, the default value provides the option value.
Copy file name to clipboardExpand all lines: src/DotMake.CommandLine/DotMake.CommandLine.csproj
+7-1Lines changed: 7 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -19,7 +19,13 @@
19
19
<Description>Declarative syntax for System.CommandLine via attributes for easy, fast, strongly-typed (no reflection) usage. Includes a source generator which automagically converts your classes to CLI commands and properties to CLI options or CLI arguments.</Description>
Copy file name to clipboardExpand all lines: src/TestApp/GeneratedFiles/DotMake.CommandLine.SourceGeneration/DotMake.CommandLine.SourceGeneration.CliCommandGenerator/ArgumentConverterCliCommandBuilder-f61jepm.g.cs
+7-7Lines changed: 7 additions & 7 deletions
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,5 @@
1
1
// <auto-generated />
2
-
// Generated by DotMake.CommandLine.SourceGeneration v1.5.6.0
2
+
// Generated by DotMake.CommandLine.SourceGeneration v1.5.7.0
Copy file name to clipboardExpand all lines: src/TestApp/GeneratedFiles/DotMake.CommandLine.SourceGeneration/DotMake.CommandLine.SourceGeneration.CliCommandGenerator/AsyncIntReturnCliCommandBuilder-7vdns44.g.cs
+2-1Lines changed: 2 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,5 @@
1
1
// <auto-generated />
2
-
// Generated by DotMake.CommandLine.SourceGeneration v1.5.6.0
2
+
// Generated by DotMake.CommandLine.SourceGeneration v1.5.7.0
Copy file name to clipboardExpand all lines: src/TestApp/GeneratedFiles/DotMake.CommandLine.SourceGeneration/DotMake.CommandLine.SourceGeneration.CliCommandGenerator/AsyncVoidReturnCliCommandBuilder-7ha5x0r.g.cs
+2-1Lines changed: 2 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,5 @@
1
1
// <auto-generated />
2
-
// Generated by DotMake.CommandLine.SourceGeneration v1.5.6.0
2
+
// Generated by DotMake.CommandLine.SourceGeneration v1.5.7.0
0 commit comments