CliArgumentAttributeRequired Property
Gets or sets a value indicating whether the argument is required when its parent command is invoked.
Default is auto-detected.
An option/argument will be considered required when
-
There is no property initializer and the property type is a reference type (e.g. public string Arg { get; set; }).
string is a reference type which has a null as the default value but bool and enum are value
types which already have non-null default values. Nullable<T> is a reference type, e.g. bool?.
-
There is a property initializer, but it's initialized with null or null! (SuppressNullableWarningExpression)
(e.g. public string Arg { get; set; } = null!;).
- If it's forced via attribute property Required (e.g. [CliArgument(Required = true)]).
-
If it's forced via required modifier (e.g. public required string Opt { get; set; }).
Note that for being able to use required modifier, if your target framework is below net7.0,
you also need <LangVersion>11.0</LangVersion> tag (minimum) in your .csproj file (our source generator supplies the polyfills
automatically as long as you set C# language version to 11).
An option/argument will be considered optional when
-
There is no property initializer (e.g. public bool Opt { get; set; }) but the property type is a value type
which already have non-null default value.
-
There is a property initializer, and it's not initialized with null or null! (SuppressNullableWarningExpression)
(e.g. public string Arg { get; set; } = "Default";).
- If it's forced via attribute property Required (e.g. [CliArgument(Required = false)]).
When an argument is required, the argument has to be specified on the command line and if its parent command is invoked
without it, an error message is displayed and the command handler isn't called.
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.
Namespace: DotMake.CommandLineAssembly: DotMake.CommandLine (in DotMake.CommandLine.dll) Version: 1.8.8
public bool Required { get; set; }
Property Value
Boolean