|
1 | 1 | CommandLineUtils |
2 | 2 | ================ |
3 | 3 |
|
4 | | -[](https://dev.azure.com/natemcmaster/github/_build/?definitionId=3) |
5 | | - |
| 4 | +[![Build Status][ci-badge]][ci] [![Code Coverage][codecov-badge]][codecov] |
6 | 5 | [![NuGet][nuget-badge] ![NuGet Downloads][nuget-download-badge]][nuget] |
7 | 6 |
|
| 7 | +[ci]: https://github.com/natemcmaster/CommandLineUtils/actions?query=workflow%3ACI+branch%3Amain |
| 8 | +[ci-badge]: https://github.com/natemcmaster/CommandLineUtils/workflows/CI/badge.svg |
| 9 | +[codecov]: https://codecov.io/gh/natemcmaster/CommandLineUtils |
| 10 | +[codecov-badge]: https://codecov.io/gh/natemcmaster/CommandLineUtils/branch/main/graph/badge.svg?token=l6uSsHZ8nA |
8 | 11 | [nuget]: https://www.nuget.org/packages/McMaster.Extensions.CommandLineUtils/ |
9 | 12 | [nuget-badge]: https://img.shields.io/nuget/v/McMaster.Extensions.CommandLineUtils.svg?style=flat-square |
10 | 13 | [nuget-download-badge]: https://img.shields.io/nuget/dt/McMaster.Extensions.CommandLineUtils?style=flat-square |
11 | 14 |
|
| 15 | +This project helps you create command line applications using .NET. |
| 16 | +It simplifies parsing arguments provided on the command line, validating |
| 17 | +user inputs, and generating help text. |
12 | 18 |
|
13 | | -This is a fork of [Microsoft.Extensions.CommandLineUtils](https://github.com/aspnet/Common), which is no longer under [active development](https://github.com/aspnet/Common/issues/257). This fork, on the other hand, will continue to make improvements, release updates, and accept contributions. |
14 | | - |
15 | | -The roadmap for this project is [pinned to the top of the issue list](https://github.com/natemcmaster/CommandLineUtils/issues/). |
16 | | - |
17 | | -## Install |
18 | | - |
19 | | -Install the [NuGet package][nuget] into your project. |
20 | | - |
21 | | -``` |
22 | | -PM> Install-Package McMaster.Extensions.CommandLineUtils |
23 | | -``` |
24 | | -``` |
25 | | -$ dotnet add package McMaster.Extensions.CommandLineUtils |
26 | | -``` |
| 19 | +The **roadmap** for this project is [pinned to the top of the issue list](https://github.com/natemcmaster/CommandLineUtils/issues/). |
27 | 20 |
|
28 | 21 | ## Usage |
29 | 22 |
|
30 | 23 | See [documentation](https://natemcmaster.github.io/CommandLineUtils/) for API reference, samples, and tutorials. |
31 | | -See [docs/samples/](./docs/samples/) for more examples, such as: |
| 24 | +See also [docs/samples/](./docs/samples/) for more examples, such as: |
32 | 25 |
|
| 26 | + - [Hello world](./docs/samples/hello-world/) |
33 | 27 | - [Async console apps](./docs/samples/helloworld-async/) |
34 | 28 | - [Structuring an app with subcommands](./docs/samples/subcommands/) |
35 | 29 | - [Defining options with attributes](./docs/samples/attributes/) |
36 | 30 | - [Interactive console prompts](./docs/samples/interactive-prompts/) |
37 | 31 | - [Required options and arguments](./docs/samples/validation/) |
38 | 32 |
|
| 33 | + |
| 34 | +### Installing the library |
| 35 | + |
| 36 | +This project is available as a [NuGet package][nuget]. |
| 37 | + |
| 38 | +``` |
| 39 | +$ dotnet add package McMaster.Extensions.CommandLineUtils |
| 40 | +``` |
| 41 | + |
| 42 | +### Code |
39 | 43 | `CommandLineApplication` is the main entry point for most console apps parsing. There are two primary ways to use this API, using the builder pattern and attributes. |
40 | 44 |
|
| 45 | + |
41 | 46 | ### Attribute API |
42 | 47 |
|
43 | 48 | ```c# |
@@ -73,34 +78,27 @@ public class Program |
73 | 78 | using System; |
74 | 79 | using McMaster.Extensions.CommandLineUtils; |
75 | 80 |
|
76 | | -public class Program |
77 | | -{ |
78 | | - public static int Main(string[] args) |
79 | | - { |
80 | | - var app = new CommandLineApplication(); |
| 81 | +var app = new CommandLineApplication(); |
81 | 82 |
|
82 | | - app.HelpOption(); |
83 | | - var optionSubject = app.Option("-s|--subject <SUBJECT>", "The subject", CommandOptionType.SingleValue); |
84 | | - var optionRepeat = app.Option<int>("-n|--count <N>", "Repeat", CommandOptionType.SingleValue); |
| 83 | +app.HelpOption(); |
| 84 | +var optionSubject = app.Option("-s|--subject <SUBJECT>", "The subject", CommandOptionType.SingleValue); |
| 85 | +var optionRepeat = app.Option<int>("-n|--count <N>", "Repeat", CommandOptionType.SingleValue); |
85 | 86 |
|
86 | | - app.OnExecute(() => |
87 | | - { |
88 | | - var subject = optionSubject.HasValue() |
89 | | - ? optionSubject.Value() |
90 | | - : "world"; |
91 | | - |
92 | | - var count = optionRepeat.HasValue() ? optionRepeat.ParsedValue : 1; |
93 | | - for (var i = 0; i < count; i++) |
94 | | - { |
95 | | - Console.WriteLine($"Hello {subject}!"); |
96 | | - } |
97 | | - return 0; |
98 | | - }); |
99 | | - |
100 | | - return app.Execute(args); |
| 87 | +app.OnExecute(() => |
| 88 | +{ |
| 89 | + var subject = optionSubject.HasValue() |
| 90 | + ? optionSubject.Value() |
| 91 | + : "world"; |
| 92 | + |
| 93 | + var count = optionRepeat.HasValue() ? optionRepeat.ParsedValue : 1; |
| 94 | + for (var i = 0; i < count; i++) |
| 95 | + { |
| 96 | + Console.WriteLine($"Hello {subject}!"); |
101 | 97 | } |
102 | | -} |
| 98 | + return 0; |
| 99 | +}); |
103 | 100 |
|
| 101 | +return app.Execute(args); |
104 | 102 | ``` |
105 | 103 |
|
106 | 104 | ### Utilities |
@@ -129,3 +127,7 @@ The library also includes other utilities for interaction with the console. Thes |
129 | 127 | ``` |
130 | 128 |
|
131 | 129 | And more! See the [documentation](https://natemcmaster.github.io/CommandLineUtils/) for more API, such as `IConsole`, `IReporter`, and others. |
| 130 | +
|
| 131 | +## Project origin and status |
| 132 | + |
| 133 | +This is a fork of [Microsoft.Extensions.CommandLineUtils](https://github.com/aspnet/Common), which is no longer under [active development](https://github.com/aspnet/Common/issues/257). This fork, on the other hand, will continue to make improvements, release updates, and accept contributions. It is currently maintained by [@natemcmaster](https://github.com/natemcmaster). |
0 commit comments