CLArgumentParser 1.0.4
dotnet add package CLArgumentParser --version 1.0.4
NuGet\Install-Package CLArgumentParser -Version 1.0.4
<PackageReference Include="CLArgumentParser" Version="1.0.4" />
<PackageVersion Include="CLArgumentParser" Version="1.0.4" />
<PackageReference Include="CLArgumentParser" />
paket add CLArgumentParser --version 1.0.4
#r "nuget: CLArgumentParser, 1.0.4"
#:package CLArgumentParser@1.0.4
#addin nuget:?package=CLArgumentParser&version=1.0.4
#tool nuget:?package=CLArgumentParser&version=1.0.4
Command-line-argument-parser
This is a simple command line argument parser that pretend be configurated with just one string pattern.
The pattern describes the way arguments shuuld be interpteted
Especification:
The string pattern has four parts: CaseSensitive, ArgCharName, ArgCharValue, args.
And have this form: [CaseSensitive] [ArgCharName:c] [ArgCharValue:c] args:<argument list specification>
Just args is mandatory
CaseSensitive: optional. Indicates the parameters will be case sensitive, case insensitive if not especified.
ArgCharName: optional. It's the prefix for each named argument, by default hyphen - ; example ArgCharName:/
ArgCharValue: optional. It's the character thar identify the asignation, by fefault colon : example ArgCharValue:=
Args: it's the pattern to extract argument values, it is a list separated by spaces. Each element of the list has the form: [*]argname[:value]
- Each argname can be prefixed with an asterisk wich means it is mandatory.
- The fixed siffix text ":value" is optional and means that a value is expected after the argument name.
- If the element doesn't have the suffix ":value" it will be a boolean parameter, it's like a switch.
- Only the argnames suffixed with ":value" can be optional.
CaseSensitive, ArgCharName and ArgCharValue are optionals, and Args must be specified.
Full example1: argcharname:/ argcharvalue:= args:*input:value output:value F S
In this example the valid arguments are:
- input: is mandatory and expects a value after the argument name
- output: is optional and must have a value after the argument is especified
- F: it's a switch
- S: it's a switch
Full example2: argcharname:/ argcharvalue:= casesensitive args:*input:value output:value F S f
In this example the arguments are case sensitive the valid arguments are:
- input: is mandatory and expects a value after the argument name
- output: is optional and must have a value after the argument is especified
- F: it's a switch
- S: it's a switch
- f: it's a switch
Using the class:
static void Main(string[] args)
{
// The arguments of this program should be:
// First, they are case sensitive
// Argument names must start with a slash /
// There are two valued arguments: /input and /output
// The value of each argument will be separated with an equal sign
// There are two switches: /S and /F
// Configure parameters in a single line:
ArgumentParser argumentParser = new ArgumentParser("argcharname:/ argcharvalue:= CaseSensitive args:*input:value output:value F S");
try
{
argumentParser.Parse(args);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
Console.WriteLine("\nUSAGE:\n");
// The class have a useful function that shows the list of parameters in console.
argumentParser.ShowUsage(System.Reflection.Assembly.GetExecutingAssembly().Location);
return;
}
Console.WriteLine("Executed as: {0}", Environment.CommandLine);
// And using the functions GetArgumentValue and GetSwitch you can get the argument values
Console.WriteLine("Argument /input value: {0}", argumentParser.GetArgumentValue("input"));
Console.WriteLine("Argument /output value: {0}", argumentParser.GetArgumentValue("output"));
Console.WriteLine("Argument /F value: {0}", argumentParser.GetSwitch("F"));
Console.WriteLine("Argument /F value: {0}", argumentParser.GetSwitch("S"));
Console.Write("End.");
Console.ReadLine();
}
}
For instance, if you run:
program.exe /input="archivo datos.in" /output=archivo.out /F /S
The result will be:
Argument /input value: archivo datos.in
Argument /output value: archivo.out
Argument /F value: True
Argument /F value: True
Version 1.0.2
- Now you can add a description for each argument with the function
void SetDescription(string argumentName, string description)
. This description will appear with the usage output.
Now usage can show descriptions for each argument, por example:
program.exe /input=samplevalue /output=samplevalue /F /S
The following arguments are mandatories: /input
Argument names are case sensitive
Arguments:
/input : input json file
/F : Force
/S : Save output to default file
Hope you enjoy it.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net6.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.