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
/// Represents a single flag argument of a command line parser. In contrast to named arguments, flag arguments, cannot be explicitly assigned a value, but rather get their value from their presence or absence.
12
12
/// </summary>
13
13
/// <typeparam name="T">
14
-
/// The type of the argument. May only be a boolean, integer, or enumeration type. When the type is boolean, then only the presence or absence of the flag is determined. If the type is an integer type (i.e. byte, sbyte,
14
+
/// The type of the argument may only be a boolean, integer, or enumeration type. When the type is boolean, then only the presence or absence of the flag is determined. If the type is an integer type (i.e. byte, sbyte,
15
15
/// short, ushort, int, uint, long, or ulong), then the number of occurrences is determined. But if the type is an enumeration type, then the number of occurrences is interpreted as the enumeration value. For example
16
16
/// consider the following enumeration type: <c>enum Severity { None = 0, Low = 1, Medium = 2, High = 3 }</c>, which is the type of the flag argument named "severity" with the alias "s", then the following command line
17
17
/// argument "-sss" would parse to an enumeration value of <c>Severity.High</c>.
Copy file name to clipboardExpand all lines: source/Arguments/PositionalArgument.cs
+16-4Lines changed: 16 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -1,8 +1,8 @@
1
1
namespaceSystem.CommandLine.Arguments
2
2
{
3
3
/// <summary>
4
-
/// Represents a single positional argument of a command line parser. A positional argument, in contrast to a named or flag argument, is an argument, which is only comprised of a value. They are not optional and must
5
-
/// be at the beginning of the command line arguments in exactly the same order as they were declared.
4
+
/// Represents a single positional argument of a command line parser. A positional argument, in contrast to a named or flag argument, is an argument, which is only comprised of a value.
5
+
/// They are not optional and must be at the beginning of the command line arguments in exactly the same order as they were declared.
6
6
/// </summary>
7
7
/// <typeparam name="T">The type of the positional argument.</param>
8
8
publicclassPositionalArgument<T>:Argument
@@ -18,7 +18,19 @@ public class PositionalArgument<T> : Argument
18
18
/// </param>
19
19
/// <param name="help">A descriptive help text for the argument, which is used in the help string.</param>
20
20
/// <exception cref="ArgumentNullException">If either the name or the destination are <c>null</c>, empty, or only consist of white spaces then an <see cref="ArgumentNullException"/> is thrown.</exception>
/// Initializes a new <see cref="PositionalArgument"/> instance.
25
+
/// </summary>
26
+
/// <param name="name">The name of the positional argument, which is used in the help string.</param>
27
+
/// <param name="alias">The alias name of the argument.</param>
28
+
/// <param name="destination">
29
+
/// The name that the positional argument will have in the result dictionary after parsing. This should adhere to normal C# naming standards. If it does not, it is automatically converted.
30
+
/// </param>
31
+
/// <param name="help">A descriptive help text for the argument, which is used in the help string.</param>
32
+
/// <exception cref="ArgumentNullException">If either the name or the destination are <c>null</c>, empty, or only consist of white spaces then an <see cref="ArgumentNullException"/> is thrown.</exception>
/// Adds a positional argument to the command line parser.
415
415
/// </summary>
416
416
/// <param name="name">The name of the positional argument, which is used in the help string.</param>
417
+
/// <param name="alias">The alias name of the argument.</param>
417
418
/// <param name="help">A descriptive help text for the argument, which is used in the help string.</param>
418
419
/// <typeparam name="T">The type of the positional argument.</typeparam>
419
420
/// <exception cref="ArgumentNullException">If the name is <c>null</c>, empty, or only consists of white spaces, then an <see cref="ArgumentNullException"/> is thrown.</exception>
420
421
/// <exception cref="InvalidOperationException">If there already is an argument with the same name, then an <see cref="InvalidOperationException"/> is thrown.</exception>
421
422
/// <returns>Returns this command line parser so that method invocations can be chained.</returns>
/// Adds a positional argument to the command line parser.
426
427
/// </summary>
427
428
/// <param name="name">The name of the positional argument, which is used in the help string.</param>
429
+
/// <param name="alias">The alias name of the argument.</param>
428
430
/// <param name="destination">
429
431
/// The name that the positional argument will have in the result dictionary after parsing. This should adhere to normal C# naming standards. If it does not, it is automatically converted.
/// <exception cref="InvalidOperationException">If there already is an argument with the same name, then an <see cref="InvalidOperationException"/> is thrown.</exception>
434
436
/// <typeparam name="T">The type of the positional argument.</typeparam>
435
437
/// <returns>Returns this command line parser so that method invocations can be chained.</returns>
/// Adds a named argument to the command line parser.
544
+
/// </summary>
545
+
/// <param name="newNamedArgument">An instance of a new named argument.</param>
546
+
/// <exception cref="InvalidOperationException">If there already is an argument with the same name or the same alias, then an <see cref="InvalidOperationException"/> is thrown.</exception>
547
+
/// <typeparam name="T">The type of the argument.</typeparam>
548
+
/// <returns>Returns this command line parser so that method invocations can be chained.</returns>
/// <param name="name">The name of the argument, which is used for parsing and in the help string.</param>
551
564
/// <exception cref="ArgumentNullException">If the name is <c>null</c>, empty, or only consists of white spaces, then an <see cref="ArgumentNullException"/> is thrown.</exception>
552
565
/// <exception cref="InvalidOperationException">If there already is an argument with the same name, then an <see cref="InvalidOperationException"/> is thrown.</exception>
553
-
/// <typeparam name="T">The type of the argument.</typeparam>
566
+
/// <typeparam name="T">The type of the argument; see FlagArgument class for allowed types.</typeparam>
554
567
/// <returns>Returns this command line parser so that method invocations can be chained.</returns>
/// <param name="alias">The alias name of the argument.</param>
562
575
/// <exception cref="ArgumentNullException">If the name is <c>null</c>, empty, or only consists of white spaces, then an <see cref="ArgumentNullException"/> is thrown.</exception>
563
576
/// <exception cref="InvalidOperationException">If there already is an argument with the same name or the same alias, then an <see cref="InvalidOperationException"/> is thrown.</exception>
564
-
/// <typeparam name="T">The type of the argument.</typeparam>
577
+
/// <typeparam name="T">The type of the argument; see FlagArgument class for allowed types.</typeparam>
565
578
/// <returns>Returns this command line parser so that method invocations can be chained.</returns>
/// <param name="help">A descriptive help text for the argument, which is used in the help string.</param>
574
587
/// <exception cref="ArgumentNullException">If the name is <c>null</c>, empty, or only consists of white spaces, then an <see cref="ArgumentNullException"/> is thrown.</exception>
575
588
/// <exception cref="InvalidOperationException">If there already is an argument with the same name or the same alias, then an <see cref="InvalidOperationException"/> is thrown.</exception>
576
-
/// <typeparam name="T">The type of the argument.</typeparam>
589
+
/// <typeparam name="T">The type of the argument; see FlagArgument class for allowed types.</typeparam>
577
590
/// <returns>Returns this command line parser so that method invocations can be chained.</returns>
/// <param name="help">A descriptive help text for the argument, which is used in the help string.</param>
587
600
/// <exception cref="ArgumentNullException">If either the name or the destination are <c>null</c>, empty, or only consist of white spaces, then an <see cref="ArgumentNullException"/> is thrown.</exception>
588
601
/// <exception cref="InvalidOperationException">If there already is an argument with the same name or the same alias, then an <see cref="InvalidOperationException"/> is thrown.</exception>
589
-
/// <typeparam name="T">The type of the argument.</typeparam>
602
+
/// <typeparam name="T">The type of the argument; see FlagArgument class for allowed types.</typeparam>
590
603
/// <returns>Returns this command line parser so that method invocations can be chained.</returns>
/// Adds a flag argument to the command line parser.
618
+
/// </summary>
619
+
/// <param name="newFlagArgument">An instance of a FlagArgument.</param>
620
+
/// <exception cref="InvalidOperationException">If there already is an argument with the same name or the same alias, then an <see cref="InvalidOperationException"/> is thrown.</exception>
621
+
/// <typeparam name="T">The type of the argument; see FlagArgument class for allowed types.</typeparam>
622
+
/// <returns>Returns this command line parser so that method invocations can be chained.</returns>
// Copies the command line arguments into a queue so that they are easier to parse without having to do fancy indexing, the first token is dequeued right away, because it is the file name of the executable
Copy file name to clipboardExpand all lines: test/ParserTests.cs
+5-5Lines changed: 5 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -781,32 +781,32 @@ public void TestComplexScenario()
781
781
782
782
// Creates the parser for the add command
783
783
ParseraddCommandParser=parser.AddCommand("add","Add a new package or reference to a .NET project.");
784
-
addCommandParser.AddPositionalArgument<string>("project","The project file to operate on.");
784
+
addCommandParser.AddPositionalArgument<string>("project","The project file to operate on.",null);
785
785
addCommandParser.AddFlagArgument<bool>("help","h","Show command line help.");
786
786
787
787
// Creates the parser for the add package command
788
788
ParseraddPackageCommandParser=addCommandParser.AddCommand("package","Add a NuGet package reference to the project.");
789
-
addPackageCommandParser.AddPositionalArgument<string>("package-name","The package reference to add.");
789
+
addPackageCommandParser.AddPositionalArgument<string>("package-name","The package reference to add.",null);
790
790
addPackageCommandParser.AddFlagArgument<bool>("help","h","Show command line help.");
791
791
addPackageCommandParser.AddNamedArgument<string>("version","v","The version of the package to add.");
792
792
addPackageCommandParser.AddFlagArgument<bool>("interactive",null,"Show command line help.");
793
793
794
794
// Creates the parser for the add reference command
795
795
ParseraddReferenceCommandParser=addCommandParser.AddCommand("reference","Add a project-to-project reference to the project.");
796
-
addReferenceCommandParser.AddPositionalArgument<string>("project-path","The paths to the projects to add as references.");
796
+
addReferenceCommandParser.AddPositionalArgument<string>("project-path","The paths to the projects to add as references.",null);
797
797
addReferenceCommandParser.AddFlagArgument<bool>("help","h","Show command line help.");
798
798
addReferenceCommandParser.AddNamedArgument<string>("framework","f","Add the reference only when targeting a specific framework.");
799
799
800
800
// Creates the parser for the build command
801
801
ParserbuildCommandParser=parser.AddCommand("build","Add a new package or reference to a .NET project.");
802
-
buildCommandParser.AddPositionalArgument<string>("project","The project file to operate on.");
802
+
buildCommandParser.AddPositionalArgument<string>("project","The project file to operate on.",null);
803
803
buildCommandParser.AddFlagArgument<bool>("help","h","Show command line help.");
804
804
buildCommandParser.AddNamedArgument<VerbosityLevel>("verbosity","v","Set the MSBuild verbosity level. Allowed values are quiet, minimal, normal, detailed, and diagnostic.");
805
805
buildCommandParser.AddNamedArgument<string>("framework","f","The target framework to build for. The target framework must also be specified in the project file.");
806
806
807
807
// Creates the parser for the new command
808
808
ParsernewCommandParser=parser.AddCommand("new","Create a new .NET project or file.");
809
-
newCommandParser.AddPositionalArgument<string>("template","The project template to use.");
809
+
newCommandParser.AddPositionalArgument<string>("template","The project template to use.",null);
810
810
newCommandParser.AddFlagArgument<bool>("help","h","Show command line help.");
811
811
newCommandParser.AddNamedArgument<string>("name","n","The name for the output being created. If no name is specified, the name of the current directory is used.");
812
812
newCommandParser.AddNamedArgument<string>("output","o","Location to place the generated output.");
0 commit comments