Skip to content

masesgroup/CLIParser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

72 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CLI Parser

CI_BUILD CI_RELEASE

CLIParser
CLIParser nuget downloads

A library to manage command-line arguments in a simple way. It was an internal MASES project, now it is available to anyone.

This project adheres to the Contributor Covenant code of conduct. By participating, you are expected to uphold this code. Please report unacceptable behavior to [email protected].

How it works

The library is very simple in its usage. The definition of command-line switches is based on generic C# types. The parser fully analyze the command line searching for switches and arguments. A special case is the one where the swithes can be inserted within an external file listing the switches line-by-line. To see a real application of the library look at project JCOReflectorCLI and JCOReflectorEngine

Argument definition

An argument can be defined using the following syntax sinppets:

arg = new ArgumentMetadata<bool>()
{
	Name = "test",
	ShortName = "tst",
	Help = "this is a test",
	Type = ArgumentType.Double,
	ValueType = ArgumentValueType.Free,
}

arg1 = new ArgumentMetadata<int>()
{
	Name = "range",
	Default = 9,
	Type = ArgumentType.Double,
	ValueType = ArgumentValueType.Range,
	MinValue = 2,
	MaxValue = 10,
}

Parser initialization

Upon arguments are defined they can be added to the list managed from the parser using:

Parser.Add(arg);

or the compact version:

arg1.Add();

Parser use

Then it is possible to use the parser on command-line arguments:

Parser.Parse(args);

or the compact version:

args.Parse();

Argument check

When the Parse method returns, a list of prepared arguments is available. The list can be used to get value or check for existence.