Skip to content

Commit 74afbfa

Browse files
authored
Merge pull request #208 from commandlineparser/readme-updates
Update README.md
2 parents 6bc4259 + 16e4257 commit 74afbfa

File tree

1 file changed

+108
-119
lines changed

1 file changed

+108
-119
lines changed

README.md

+108-119
Original file line numberDiff line numberDiff line change
@@ -4,143 +4,118 @@
44
[![Nuget](https://img.shields.io/nuget/vpre/commandlineparser.svg)](http://nuget.org/packages/commandlineparser)
55
[![Join the gitter chat!](https://badges.gitter.im/gsscoder/commandline.svg)](https://gitter.im/gsscoder/commandline?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
66

7-
Command Line Parser Library for CLR and NetStandard
8-
===
7+
# Command Line Parser Library for CLR and NetStandard
98

10-
**Note:** the API surface has changed since 1.9.x and earlier. If you are looking for documentation on 1.9.x, please see [this branch](https://github.com/gsscoder/commandline/tree/stable-1.9.71.2)
9+
**Note:** the API surface has changed since v1.9.x and earlier. If you are looking for documentation on v1.9.x, please see [stable-1.9.71.2](https://github.com/gsscoder/commandline/tree/stable-1.9.71.2)
1110

1211
The Command Line Parser Library offers CLR applications a clean and concise API for manipulating command line arguments and related tasks, such as defining switches, options and verb commands. It allows you to display a help screen with a high degree of customization and a simple way to report syntax errors to the end user.
1312

1413
```
1514
C:\Project> Nuget Install CommandLineParser
15+
```
1616

1717
or
1818

19+
```
1920
C:\Project> paket install CommandLineParser
2021
```
2122

22-
Everything that is boring and repetitive about parsing command line arguments is delegated to the library, letting developers concentrate on core logic. It's written in **C#** and doesn't depend on other packages.
23-
2423
__This library provides _hassle free_ command line parsing with a constantly updated API since 2005.__
2524

2625
Compatibility:
27-
---
2826
- .NET Framework 4.0+
2927
- Mono 2.1+ Profile
3028
- .Net Core
3129

32-
Current Release:
33-
---
34-
- For documentation please read appropriate [wiki section](https://github.com/gsscoder/commandline/wiki/Latest-Version).
35-
- From version **2.0.x-pre+** parsing kernel was rewritten and public API simplified.
30+
# At a glance:
3631

37-
At glance:
38-
---
39-
- One line parsing using default singleton: `CommandLine.Parser.Default.ParseArguments(...)`.
40-
- Automatic or one line help screen generator: `HelpText.AutoBuild(...)`.
41-
- Supports `--help`, `--version`, `version` and `help [verb]` by default.
42-
- Map to sequences (`IEnumerable<T>`) or scalar types, including enum and `Nullable<T>`.
43-
- You can also map to every type with a constructor that accepts a string (like `System.Uri`).
44-
- __Plug-In friendly__ architecture as explained [here](https://github.com/gsscoder/commandline/wiki/Plug-in-Friendly-Architecture).
45-
- Define [verb commands](https://github.com/gsscoder/commandline/wiki/Latest-Version#verbs) as `git commit -a`.
46-
- Unparsing support: `CommandLine.Parser.Default.FormatCommandLine<T>(T options)`.
47-
- F#-friendly with support for `option<'a>`, see [demo](https://github.com/gsscoder/commandline/blob/master/demo/fsharp-demo.fsx).
48-
- Most of features applies with a [CoC](http://en.wikipedia.org/wiki/Convention_over_configuration) philosophy.
49-
- C# demo: source [here](https://github.com/gsscoder/commandline/tree/master/demo/ReadText.Demo).
50-
51-
Integrate directly into your project
52-
---
53-
It is possible to integrate the CommandLineParser library directly into your project in two ways:
32+
- Doesn't depend on other packages (No dependencies beyond standard base libraries)
33+
- One line parsing using default singleton: `CommandLine.Parser.Default.ParseArguments(...)`.
34+
- Automatic or one line help screen generator: `HelpText.AutoBuild(...)`.
35+
- Supports `--help`, `--version`, `version` and `help [verb]` by default.
36+
- Map to sequences (`IEnumerable<T>`) or scalar types, including enum and `Nullable<T>`.
37+
- You can also map to every type with a constructor that accepts a string (like `System.Uri`).
38+
- __Plug-In friendly__ architecture as explained [here](https://github.com/gsscoder/commandline/wiki/Plug-in-Friendly-Architecture).
39+
- Define [verb commands](https://github.com/gsscoder/commandline/wiki/Latest-Version#verbs) as `git commit -a`.
40+
- Unparsing support: `CommandLine.Parser.Default.FormatCommandLine<T>(T options)`.
41+
- F#-friendly with support for `option<'a>`, see [demo](https://github.com/gsscoder/commandline/blob/master/demo/fsharp-demo.fsx).
42+
- Most of features applies with a [CoC](http://en.wikipedia.org/wiki/Convention_over_configuration) philosophy.
43+
- C# demo: source [here](https://github.com/gsscoder/commandline/tree/master/demo/ReadText.Demo).
5444

55-
First way is simply copy the .cs files into your project:
56-
```
57-
C:\Projects\MyProject> cp -r ClonedRepo/src/CommandLine To/Your/Project/Dir
58-
```
45+
Used by several open source projects and by various commercial products: See the [wiki for listing](https://github.com/gsscoder/commandline/Used_By)
5946

60-
You can also use ILMerge during your library build process:
47+
# Getting Started with the Command Line Parser Library
6148

62-
```
63-
C:\Projects\MyProject> msbuild MyProject.sln /p:Configuration=Release
64-
C:\Projects\MyProject> ilmerge bin\Release\MyProject.exe bin\Release\CommandLineParser.dll bin\Release\MyProject.merged.exe
65-
```
49+
You can utilize the parser library in several ways:
6650

67-
To build:
68-
---
69-
- [FAKE](http://fsharp.github.io/FAKE/) Script
70-
- MS Visual Studio
71-
- Xamarin Studio
51+
- Install via Nuget/Paket
52+
- Integrate directly into your project by copying the .cs files into your project.
53+
- ILMerge during your build process.
7254

73-
Public API:
74-
---
75-
Latest changes are recorded from Version 1.9.4.91, please refer to [this document](https://github.com/commandlineparser/commandline/blob/master/docs/PublicAPI.md).
55+
See more details in the [wiki for direct integrations](https://github.com/gsscoder/commandline/wiki/Direct_Integrations)
7656

77-
Used by:
78-
---
79-
- [FSharp.Formatting](https://github.com/tpetricek/FSharp.Formatting) by @tpetricek.
80-
- [MiniDumper](https://github.com/goldshtn/minidumper) by @goldshtn.
81-
- [Google APIs Client Library for .NET](https://github.com/google/google-api-dotnet-client) by Google.
82-
- [FSpec](https://github.com/PeteProgrammer/fspec) by @PeteProgrammer.
83-
- Various commercial products.
57+
## Quick Start Examples
8458

85-
Notes:
86-
---
87-
The project is well suited to be included in your application. If you don't merge it to your project tree, you must reference `CommandLine.dll` and import `CommandLine` and `CommandLine.Text` namespaces (or install via NuGet). The help text builder and support types are in the `CommandLine.Text` namespace that is loosely coupled with the parser. It is good to know that the `HelpText` class will avoid a lot of repetitive coding.
59+
1. Create a class to define valid options, and to receive the parsed options.
60+
2. Call ParseArguments with the args string array.
8861

89-
**C#:**
62+
C# Examples:
9063

91-
Define a class to receive parsed values:
9264
```csharp
93-
class Options {
94-
[Option('r', "read", Required = true,
95-
HelpText = "Input files to be processed.")]
65+
internal class Options {
66+
[Option('r',"read",
67+
Required = true,
68+
HelpText = "Input files to be processed.")]
9669
public IEnumerable<string> InputFiles { get; set; }
9770

98-
// Omitting long name, default --verbose
71+
// Omitting long name, defaults to name of property, ie "--verbose"
9972
[Option(
100-
HelpText = "Prints all messages to standard output.")]
73+
DefaultValue = false,
74+
HelpText = "Prints all messages to standard output.")]
10175
public bool Verbose { get; set; }
102-
103-
[Option(DefaultValue = "中文",
104-
HelpText = "Content language.")]
105-
public string Language { get; set; }
76+
77+
[Option("stdin",
78+
DefaultValue = false
79+
HelpText = "Read from stdin")]
80+
public bool stdin { get; set; }
10681

10782
[Value(0, MetaName = "offset",
108-
HelpText = "File offset.")]
83+
HelpText = "File offset.")]
10984
public long? Offset { get; set; }
11085
}
111-
```
112-
Consume them:
113-
```csharp
86+
11487
static int Main(string[] args) {
11588
var options = new Options();
11689
var isValid = CommandLine.Parser.Default.ParseArgumentsStrict(args, options);
11790
```
118-
**F#:**
91+
92+
F# Examples:
93+
11994
```fsharp
12095
type options = {
12196
[<Option('r', "read", Required = true, HelpText = "Input files.")>] files : seq<string>;
12297
[<Option(HelpText = "Prints all messages to standard output.")>] verbose : bool;
12398
[<Option(DefaultValue = "русский", HelpText = "Content language.")>] language : string;
12499
[<Value(0, MetaName="offset", HelpText = "File offset.")>] offset : int64 option;
125100
}
126-
```
127-
Consume them:
128-
```fsharp
101+
129102
let main argv =
130103
let result = CommandLine.Parser.Default.ParseArguments<options>(argv)
131104
match result with
132105
| :? Parsed<options> as parsed -> run parsed.Value
133106
| :? NotParsed<options> as notParsed -> fail notParsed.Errors
134107
```
135-
**VB.NET:**
108+
109+
VB.Net:
110+
136111
```VB.NET
137112
Class Options
138113
<CommandLine.Option('r', "read", Required := true,
139114
HelpText:="Input files to be processed.")>
140115
Public Property InputFiles As IEnumerable(Of String)
141116

142-
' Omitting long name, default --verbose
143-
<CommandLine.Option(
117+
' Omitting long name, defaults to name of property, ie "--verbose"
118+
<CommandLine.Option(
144119
HelpText:="Prints all messages to standard output.")>
145120
Public Property Verbose As Boolean
146121

@@ -152,16 +127,17 @@ Class Options
152127
HelpText:="File offset.")>
153128
Public Property Offset As Long?
154129
End Class
155-
```
156-
Consume them:
157-
```VB.NET
158-
TODO
130+
131+
'TODO
159132
```
160133

134+
### For verbs:
161135

162-
For verbs:
136+
1. Create separate option classes for each verb. An options base class is supported.
137+
2. Use MapResult to direct program flow to the verb that was parsed.
138+
139+
C# example:
163140

164-
**C#:**
165141
```csharp
166142
[Verb("add", HelpText = "Add file contents to the index.")]
167143
class AddOptions {
@@ -178,15 +154,37 @@ class CloneOptions {
178154

179155
int Main(string[] args) {
180156
return CommandLine.Parser.Default.ParseArguments<AddOptions, CommitOptions, CloneOptions>(args)
181-
.MapResult(
182-
(AddOptions opts) => RunAddAndReturnExitCode(opts),
183-
(CommitOptions opts) => RunCommitAndReturnExitCode(opts),
184-
(CloneOptions opts) => RunCloneAndReturnExitCode(opts),
185-
errs => 1);
157+
.MapResult(
158+
(AddOptions opts) => RunAddAndReturnExitCode(opts),
159+
(CommitOptions opts) => RunCommitAndReturnExitCode(opts),
160+
(CloneOptions opts) => RunCloneAndReturnExitCode(opts),
161+
errs => 1);
186162
}
187163
```
188164

189-
**F#:**
165+
VB.Net example:
166+
167+
```VB.NET
168+
<CommandLine.Verb("add", HelpText:="Add file contents to the index.")>
169+
Public Class AddOptions
170+
'Normal options here
171+
End Class
172+
<CommandLine.Verb("commit", HelpText:="Record changes to the repository.")>
173+
Public Class AddOptions
174+
'Normal options here
175+
End Class
176+
<CommandLine.Verb("clone", HelpText:="Clone a repository into a new directory.")>
177+
Public Class AddOptions
178+
'Normal options here
179+
End Class
180+
181+
Public Shared Sub Main()
182+
'TODO
183+
End Sub
184+
```
185+
186+
F# Example:
187+
190188
```fsharp
191189
open CommandLine
192190

@@ -208,54 +206,45 @@ let main args =
208206
let result = Parser.Default.ParseArguments<AddOptions, CommitOptions, CloneOptions> args
209207
match result with
210208
| :? CommandLine.Parsed<obj> as command ->
211-
match command.Value with
212-
| :? AddOptions as opts -> RunAddAndReturnExitCode opts
213-
| :? CommitOptions as opts -> RunCommitAndReturnExitCode opts
214-
| :? CloneOptions as opts -> RunCloneAndReturnExitCode opts
209+
match command.Value with
210+
| :? AddOptions as opts -> RunAddAndReturnExitCode opts
211+
| :? CommitOptions as opts -> RunCommitAndReturnExitCode opts
212+
| :? CloneOptions as opts -> RunCloneAndReturnExitCode opts
215213
| :? CommandLine.NotParsed<obj> -> 1
216214
```
217-
**VB.NET:**
218-
```VB.NET
219-
<CommandLine.Verb("add", HelpText:="Add file contents to the index.")>
220-
Public Class AddOptions
221-
'Normal options here
222-
End Class
223-
<CommandLine.Verb("commit", HelpText:="Record changes to the repository.")>
224-
Public Class AddOptions
225-
'Normal options here
226-
End Class
227-
<CommandLine.Verb("clone", HelpText:="Clone a repository into a new directory.")>
228-
Public Class AddOptions
229-
'Normal options here
230-
End Class
231215

232-
Public Shared Sub Main()
233-
'TODO
234-
End Sub
235-
```
216+
For additional examples, check the [wiki for additional examples](https://gsscoder/commandline/wiki/Examples)
236217
237218
Acknowledgements:
238219
---
239220
[![Jet Brains ReSharper](/art/resharper-logo.png)](http://www.jetbrains.com/resharper/)
240221
241222
Thanks to JetBrains for providing an open source license for [ReSharper](http://www.jetbrains.com/resharper/).
242223
243-
Main Contributors (alphabetical order):
224+
# Contibutors
225+
First off, _Thank you!_ All contributions are welcome.
226+
227+
Please consider sticking with the GNU getopt standard for command line parsing.
228+
229+
Additionally, for easiest diff compares, please follow the project's tabs settings. Utilizing the EditorConfig extension for Visual Studio/your favorite IDE is recommended.
230+
231+
For more info, see the [wiki for details about contributing](https://github.com/gsscoder/commandline/wiki/Building_the_library) and for building the project.
232+
233+
## Main Contributors (alphabetical order):
244234
- Alexander Fast (@mizipzor)
245235
- Dan Nemec (@nemec)
246236
- Kevin Moore (@gimmemoore)
247237
- Steven Evans
248238
- Thomas Démoulins (@Thilas)
249239

250-
Resources for newcomers:
251-
---
252-
- [CodePlex](http://commandline.codeplex.com)
253-
- [Quickstart](https://github.com/gsscoder/commandline/wiki/Quickstart)
254-
- [Wiki](https://github.com/gsscoder/commandline/wiki)
255-
- [GNU getopt](http://www.gnu.org/software/libc/manual/html_node/Getopt.html)
240+
## Resources for newcomers:
241+
242+
- [Quickstart](https://github.com/gsscoder/commandline/wiki/Quickstart)
243+
- [Wiki](https://github.com/gsscoder/commandline/wiki)
244+
- [GNU getopt](http://www.gnu.org/software/libc/manual/html_node/Getopt.html)
245+
246+
# Contacts:
256247

257-
Contact:
258-
---
259248
- Giacomo Stelluti Scala
260249
- gsscoder AT gmail DOT com (_use this for everything that is not available via GitHub features_)
261250
- GitHub: [gsscoder](https://github.com/gsscoder)

0 commit comments

Comments
 (0)