|
1 | 1 | # NetArgumentParser |
2 | | -Parser for command-line options and arguments. |
| 2 | +**NetArgumentParser** is a cross-platform, free and open source library for parsing command-line options and arguments. |
| 3 | + |
| 4 | +## Table of contents |
| 5 | +* [Main Features](#main-features) |
| 6 | +* [Quick Start](#quick-start) |
| 7 | + * [Build Project](#build-project) |
| 8 | + * [Test Project](#test-project) |
| 9 | + * [Connect Project](#connect-project) |
| 10 | + * [Step-By-Step Connection](#step-by-step-connection) |
| 11 | +* [Project Status And TODO List](#project-status-and-todo-list) |
| 12 | +* [Development](#development) |
| 13 | +* [Contributing](#contributing) |
| 14 | +* [License](#license) |
| 15 | + |
| 16 | +## Main Features |
| 17 | +This library supports the following main features: |
| 18 | +- Parse options starting with a minus (such as `-v`). |
| 19 | +- Parse options starting with a double minus (such as `--version`). |
| 20 | +- Parse options starting with a slash (such as `/v` or `/version`). |
| 21 | +- Parse compound options (such as `-lah`). |
| 22 | +- Parse long name options starting with a minus (such as `-version`). |
| 23 | +- Extract extra arguments. |
| 24 | +- Support custom converters. |
| 25 | +- Configure command-line help generation. |
| 26 | + |
| 27 | +## Quick Start |
| 28 | +To start working with the library you need to build it and then connect it to your project. |
| 29 | + |
| 30 | +### Build Project |
| 31 | +You can [build](https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-build) the library with the following command, which should be run from the root of the library. |
| 32 | +``` |
| 33 | +dotnet build |
| 34 | +``` |
| 35 | + |
| 36 | +### Test Project |
| 37 | +You can [test](https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-test) the library with the following command, which should be run from the root of the library. |
| 38 | +``` |
| 39 | +dotnet test |
| 40 | +``` |
| 41 | + |
| 42 | +### Connect Project |
| 43 | +At fitst, you need to [add reference](https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-add-reference) to the library: |
| 44 | +``` |
| 45 | +dotnet add reference /Path/To/Lib/Core/NetArgumentParser |
| 46 | +``` |
| 47 | + |
| 48 | +Next, you need to add the usings you need: |
| 49 | +```cs |
| 50 | +using NetArgumentParser; |
| 51 | +using NetArgumentParser.Converters; |
| 52 | +using NetArgumentParser.Generators; |
| 53 | +using NetArgumentParser.Options; |
| 54 | +using NetArgumentParser.Options.Context; |
| 55 | +``` |
| 56 | + |
| 57 | +Finally, you can work with the parser. |
| 58 | + |
| 59 | +### Step-By-Step Connection |
| 60 | +Let's consider this step-by-step instructions for creating a sample project and connecting this library to it. |
| 61 | +- Step 1: Go to the directory with your projects. |
| 62 | +``` |
| 63 | +cd ~/Repos |
| 64 | +``` |
| 65 | +- Step 2: Create folder for your project and go to it. |
| 66 | +``` |
| 67 | +mkdir MyProject && cd MyProject |
| 68 | +``` |
| 69 | +- Step 3: Create solution. |
| 70 | +``` |
| 71 | +dotnet new sln |
| 72 | +``` |
| 73 | +- Step 4: Create your project. |
| 74 | +``` |
| 75 | +dotnet new console -o MyProject |
| 76 | +``` |
| 77 | +- Step 5: Add your project to the solution. |
| 78 | +``` |
| 79 | +dotnet sln add ./MyProject |
| 80 | +``` |
| 81 | +- Step 6: Add folder for external projects and go to it. |
| 82 | +``` |
| 83 | +mkdir Vendor && cd Vendor |
| 84 | +``` |
| 85 | +- Step 7: Clone **NetArgumentParser** repository. |
| 86 | +``` |
| 87 | +git clone https://github.com/yakovypg/NetArgumentParser.git |
| 88 | +``` |
| 89 | +- Step 8: Go back to the root folder. |
| 90 | +``` |
| 91 | +cd .. |
| 92 | +``` |
| 93 | +- Step 9: Add **NetArgumentParser** to the solution. |
| 94 | +``` |
| 95 | +dotnet sln add Vendor/NetArgumentParser/Core/NetArgumentParser |
| 96 | +``` |
| 97 | +- Step 10: Go to your project folder. |
| 98 | +``` |
| 99 | +cd MyProject |
| 100 | +``` |
| 101 | +- Step 11: Add reference to the **NetArgumentParser**. |
| 102 | +``` |
| 103 | +dotnet add reference ../Vendor/NetArgumentParser/Core/NetArgumentParser |
| 104 | +``` |
| 105 | +- Step 12: Open Program.cs file and try using the **NetArgumentParser**. |
| 106 | +```cs |
| 107 | +using System; |
| 108 | +using System.Collections.Generic; |
| 109 | +using NetArgumentParser; |
| 110 | +using NetArgumentParser.Options; |
| 111 | + |
| 112 | +int? angle = default; |
| 113 | + |
| 114 | +var option = new ValueOption<int>("angle", "a", |
| 115 | + description: "angle by which you want to rotate the image", |
| 116 | + afterValueParsingAction: t => angle = t); |
| 117 | + |
| 118 | +var parser = new ArgumentParser(); |
| 119 | +parser.AddOptions(option); |
| 120 | +parser.ParseKnownArguments(args, out List<string> extraArguments); |
| 121 | + |
| 122 | +Console.WriteLine($"Angle: {angle}"); |
| 123 | +Console.WriteLine($"Extra arguments: {string.Join(' ', extraArguments)}"); |
| 124 | +``` |
| 125 | +- Step 13: Build the project. |
| 126 | +``` |
| 127 | +dotnet build -c Release |
| 128 | +``` |
| 129 | +- Step 14: Run the created application. |
| 130 | +``` |
| 131 | +dotnet run --angle 45 A |
| 132 | +``` |
| 133 | + |
| 134 | +## Project Status And TODO List |
| 135 | +**NetArgumentParser** is currently under development. There are some features that need to be added to the project: |
| 136 | +- Add support of subcommands. |
| 137 | +- Add counter option. |
| 138 | +- Add support of custom option prefix characters. |
| 139 | +- Add support of custom assignment characters. |
| 140 | +- Add support of reflection-based configuring option set using special attributes. |
| 141 | +- Add support of restricting the set of values for an argument. |
| 142 | +- Add support of hidden arguments and aliases. |
| 143 | +- Add support of import and export JSON configuration. |
| 144 | +- Add support of parent parsers. |
| 145 | +- Add NuGet package. |
| 146 | + |
| 147 | +## Documentation |
| 148 | +You can find documentation in the [Docs](Docs) folder. |
| 149 | + |
| 150 | +## Development |
| 151 | +The project is developed on the .NET 8.0 platform. To continue development you will need the .NET SDK and .NET Runtime of the appropriate version. |
| 152 | + |
| 153 | +## Contributing |
| 154 | +Contributions are welcome, have a look at the [CONTRIBUTING.md](CONTRIBUTING.md) document for more information. |
| 155 | + |
| 156 | +## License |
| 157 | +The project is available under the [GPL-3.0](LICENSE) license. |
0 commit comments