https://github.com/masesgroup/cliparser
A library to manage command-line arguments in a simple way.
https://github.com/masesgroup/cliparser
cli command-line command-line-tool dotnet dotnet-core dotnet-framework dotnet6 dotnetcore net6 netstandard netstandard20 parser
Last synced: about 1 year ago
JSON representation
A library to manage command-line arguments in a simple way.
- Host: GitHub
- URL: https://github.com/masesgroup/cliparser
- Owner: masesgroup
- License: mit
- Created: 2021-08-29T21:30:14.000Z (almost 5 years ago)
- Default Branch: master
- Last Pushed: 2024-10-07T05:07:47.000Z (over 1 year ago)
- Last Synced: 2025-04-01T11:51:30.485Z (about 1 year ago)
- Topics: cli, command-line, command-line-tool, dotnet, dotnet-core, dotnet-framework, dotnet6, dotnetcore, net6, netstandard, netstandard20, parser
- Language: C#
- Homepage: https://cliparser.masesgroup.com/
- Size: 16.8 MB
- Stars: 1
- Watchers: 1
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- Funding: .github/FUNDING.yml
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# CLI Parser
[](https://github.com/masesgroup/CLIParser/actions/workflows/build.yaml) [](https://github.com/masesgroup/CLIParser/actions/workflows/release.yaml)
|CLIParser |
|--- |
|[](https://www.nuget.org/packages/MASES.CLIParser) [](https://www.nuget.org/packages/MASES.CLIParser) |
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](https://github.com/masesgroup/DataDistributionManager/blob/master/CODE_OF_CONDUCT.md). By participating, you are expected to uphold this code. Please report unacceptable behavior to coc_reporting@masesgroup.com.
## 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](https://github.com/masesgroup/JCOReflector/tree/master/JCOReflector/CLI) and [JCOReflectorEngine](https://github.com/masesgroup/JCOReflector/blob/master/JCOReflector/engine/SharedClasses.cs)
### Argument definition
An argument can be defined using the following syntax sinppets:
```C#
arg = new ArgumentMetadata()
{
Name = "test",
ShortName = "tst",
Help = "this is a test",
Type = ArgumentType.Double,
ValueType = ArgumentValueType.Free,
}
arg1 = new ArgumentMetadata()
{
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:
```C#
Parser.Add(arg);
```
or the compact version:
```C#
arg1.Add();
```
### Parser use
Then it is possible to use the parser on command-line arguments:
```C#
Parser.Parse(args);
```
or the compact version:
```C#
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.