-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCommandLine.Notes.txt
147 lines (92 loc) · 3.4 KB
/
CommandLine.Notes.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
CommandLine Parser Extensions
=============================
Problems with CommandLine:
- Help screen not consistent between invoked automatically on error or via HelpBuilder
- Help text not customisable enough (doesn't show command line structure)
- Parser customisation done inline away from Arguments classes and the defaults are not ideal
- --help/--version interception to display help screen other than the default
Links
-----
https://github.com/gsscoder/commandline/wiki/Latest-Version#usage-attribute
https://github.com/gsscoder/commandline/wiki/Display-A-Help-Screen
Usage
-----
Parser.Default
returns a Parser instance
Configuration
-------------
var parser = new Parser(config => config.HelpWriter = Console.Out);
Single Options
--------------
var result = parser.ParseArguments<T>(args);
returns a ParserResult<T>
which is really a Parsed<T> or NotParsed<T>
or can do
var result = parser.ParseArguments<T>(args)
.WithParsed(options => ...) // Type T
.WithNotParsed(errors => ...) // IEnumerable<Error>
or even
var returnCode = parser.ParseArguments<T>(args)
.MapResult(
options => RunAndReturnExitCode(options),
_ => 1
);
Verbs
-----
var result = parser.ParseArguments<T1, T2, T2>(args)
.WithParsed<T1>(opts => ...)
.WithParsed<T2>(opts => ...)
.WithParsed<T3>(opts => ...)
.WithNotParsed(errors => ...)
or
var returnCode = parser.ParseArguments<T1, T2, T3>(args)
.MapResult(
(T1 options) => RunT1AndReturnExitCode(options),
(T2 options) => RunT2AndReturnExitCode(options),
(T3 options) => RunT3AndReturnExitCode(options),
errs => 1
);
Built in Commands
-----------------
--help triggers help output
--version triggers version output
only via the default configured HelpWriter though
Sample Output
-------------
----------------------------------------------------------------------------------------------------
Default output from ParseArguments<>
CommandLine 2.0.275-beta
Copyright (c) 2005 - 2015 Giacomo Stelluti Scala
ERROR(S):
Required option 'p, position' is missing.
A required value not bound to option name is missing.
USAGE:
Default:
CommandLine [filename]
-p, --position Required. Where to start from
-l, --lines (Default: 5) How many lines to process
--help Display this help screen.
--version Display version information.
FileName (pos. 0) Required. The filename to process
----------------------------------------------------------------------------------------------------
Customising via HelpText.AutoBuild
CommandLine 2.0.275-beta
Copyright (c) 2005 - 2015 Giacomo Stelluti Scala
USAGE:
Default:
CommandLine [filename]
-p, --position Required. Where to start from Valid values: Above, Below
-l, --lines (Default: 5) How many lines to process
--help Display this help screen.
--version Display version information.
FileName (pos. 0) Required. The filename to process
----------------------------------------------------------------------------------------------------
Templated help from DNX.Helpers.CommandLine
Test.DNX.Helpers.CommandLine v1 -
Copyright © 2017 DNX Solutions Ltd
Usage:
Test.DNX.Helpers.CommandLine.dll [FileName] { [options] }
Options:
-p, --position Where to start from
-l, --lines How many lines to process
-?, --help Display this Help page