Argument parser uses description generator to geterate command-line help. If you don't specify it, the default generator will be used.
You can specify name, version, description and epilog of your program. To do this, you need to set values in the corresponding properties, as shown in the example below.
var parser = new ArgumentParser()
{
ProgramName = "ProgramName",
ProgramVersion = "ProgramName v1.0.0",
ProgramDescription = "What the program does",
ProgramEpilog = "Text at the bottom"
};
The output will be like the following:
Usage: ProgramName ...
What the program does
Options:
...
Text at the bottom
NetArgumentParser allows you to customize the generating of command-line help. You can configure an existing generator or create your own.
You can change header of the usage
section, header of the subcommands
section and a default option group header.
To change a header of the usage
section you need to create description generator and specify corresponding property in it. You can do this the same way as in the following example.
var parser = new ArgumentParser();
var generator = new ApplicationDescriptionGenerator(parser)
{
UsageHeader = "My Usage: "
};
parser.DescriptionGenerator = generator;
The output will be like the following:
My Usage: ...
Options:
...
You can change a default option group header. You can do this the same way as in the following example.
var parser = new ArgumentParser();
parser.DefaultGroup.Header = "Default group:";
The output will be like the following:
Usage: ...
Default group:
...
To change a header of the subcommands
section you need to create description generator and specify corresponding property in it. You can do this the same way as in the following example.
var parser = new ArgumentParser();
var generator = new ApplicationDescriptionGenerator(parser)
{
SubcommandsHeader = "My Subcommands:"
};
parser.DescriptionGenerator = generator;
The output will be like the following:
Usage: ...
Options:
...
My Subcommands: ...
...
You can change the following delimiters:
- Before and after option example.
- Before and after subcommand name.
You can change delimiters before and after option example. You can do this the same way as in the following example.
var parser = new ArgumentParser();
var generator = new ApplicationDescriptionGenerator(parser)
{
OptionExamplePrefix = "@@",
DelimiterAfterOptionExample = " -> "
};
parser.DescriptionGenerator = generator;
The output will be like the following:
Usage: ...
Options:
@@--angle ANGLE, -a ANGLE -> angle by which you want to rotate the image
@@--version -> show version information
You can change delimiters before and after subcommand name. You can do this the same way as in the following example.
var parser = new ArgumentParser();
var generator = new ApplicationDescriptionGenerator(parser)
{
SubcommandNamePrefix = "@@",
DelimiterAfterSubcommandName = " -> "
};
parser.DescriptionGenerator = generator;
The output will be like the following:
Usage: ...
Options:
...
Subcommands:
@@resize -> resize the image
You can specify window width and maximum space for option example.
The width of the window is set in order to correctly wrap the components of the command-line help. The easiest way to set the width is using the Console.WindowWidth
property. You can do it like this:
var parser = new ArgumentParser();
var generator = new ApplicationDescriptionGenerator(parser)
{
WindowWidth = Console.WindowWidth
};
parser.DescriptionGenerator = generator;
You can specify a character limit for the option examples. This is useful for small windows to prevent running out of space to describe options. The default value for this limit is 30, but you can change it as follows:
var parser = new ArgumentParser();
var generator = new ApplicationDescriptionGenerator(parser)
{
OptionExampleCharsLimit = 25
};
parser.DescriptionGenerator = generator;
You can change output stream in which all information and messages are written. To do this you need to create a custom class inherited from the ITextWriter
interface and pass it to the ChangeOutputWriter()
method. You can also use an existing text writer class as a base class. See example of this kind of inheritance, for example, by looking at the implementation of the ConsoleTextWriter
class.
var parser = new ArgumentParser();
parser.ChangeOutputWriter(new ConsoleTextWriter());
You can create your own application description generator and subcommand description generator. This can be useful if you want to implement your own command-line help generation system.
You can create your own application description generator. To do this you need to inherit your class from the IDescriptionGenerator
interface and implement it. You can also use an existing ParserQuantumDescriptionGenerator
class as a base class. See example of this kind of inheritance, for example, by looking at the implementation of the ApplicationDescriptionGenerator
class. Next, you can use this class in the same way as the standard ones.
var parser = new ArgumentParser();
var generator = new ApplicationDescriptionGenerator(parser);
parser.DescriptionGenerator = generator;
You can create your own subcommand description generator. To do this you need to inherit your class from the IDescriptionGenerator
interface and implement it. You can also use an existing ParserQuantumDescriptionGenerator
class as a base class. See example of this kind of inheritance, for example, by looking at the implementation of the SubcommandDescriptionGenerator
class. Next, you can use this class in the same way as the standard ones.
var parser = new ArgumentParser()
{
SubcommandDescriptionGeneratorCreator = t => new SubcommandDescriptionGenerator(t)
};