-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathman.3
225 lines (193 loc) · 4.01 KB
/
man.3
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
.TH "opts.js" "3"
.PP
Find the full documentation, source code, and examples at \fIhttps://khtdr.com/opts\fP
.SH "NAME"
.PP
opts.js - a command line parser for options and arguments
.SH "VERSION"
.PP
v2.0.2
.SH "SYNOPSIS"
.PP
The following example uses a custom \fBversion\fP function, and opts in to the automatic help text. No pun intended.
.RS
.nf
\fCvar opts = require('opts');
var options = [
{ short : 'v'
, long : 'version'
, description : 'Show version and exit'
, callback : function () { console.log('v1.0'); process.exit(1); }
}
];
opts.parse(options, true);
console.log('Example 1');
process.exit(0);
\fP
.fi
.RE
.PP
See \fIhttps://raw.githubusercontent.com/khtdr/opts/master/examples/example1.js\fP
.SS "running:"
.RS
.nf
\fC$ node ./example1
\fP
.fi
.RE
.SS "produces:"
.RS
.nf
\fCExample 1
\fP
.fi
.RE
.SS "running:"
.RS
.nf
\fC$ node ./example1 --help
\fP
.fi
.RE
.SS "produces:"
.RS
.nf
\fCUsage: node ./example1 [options]
Show this help message
--help
Show version and exit
-v, --version
\fP
.fi
.RE
.SS "running:"
.RS
.nf
\fCnode ./example1 -v
\fP
.fi
.RE
.SS "produces:"
.RS
.nf
\fCv1.0
\fP
.fi
.RE
.SH "INSTALLATION"
.PP
You do not need to use NPM or any package manager. It is written in plain-old Javascript and can be downloaded and included in your Node.js project, as-is. All of the examples use this approach.
.RE
See \fIhttps://github.com/khtdr/opts/tree/master/examples\fP
.SS "Stand-alone version"
.RS
.nf
\fCcd /path/to/your/project
curl -o opts.js https://raw.githubusercontent.com/khtdr/opts/master/src/opts.js
\fP
.fi
.RE
.SS "NPM version"
.RS
.nf
\fCnpm install opts
\fP
.fi
.RE
.SH "USAGE"
.SS "LOADING"
.PP
With classic syntax:
.RS
.nf
\fCvar opts = require('opts');
opts.parse(options, arguments, help);
\fP
.fi
.RE
.PP
With modern syntax:
.RS
.nf
\fCimport * as opts from 'opts';
opts.parse(options, arguments, help);
\fP
.fi
.RE
.PP
If you installed \fCopts\fP with NPM, the typescript definitions should automatically be available in your editor. Otherwise you can download the .d.ts file manually.
.RE
See \fIhttps://raw.githubusercontent.com/khtdr/opts/master/src/opts.d.ts\fP
.SS "CONFIGURING"
.PP
\fIopts.parse(options, arguments, help)\fP
.PP
Options are flag-arguments. Arguments are everything else. Consider the following hypothetical command for starting a server that listens on \fIhttp://0.0.0.0:4000\fP
.RS
.nf
\fCnode ./my-app start --host 0.0.0.0 -p 4000
\fP
.fi
.RE
.PP
In this example, the options are \fI\-\-host 0.0.0.0\fP and \fI\-p 4000\fP. The argument is \fIstart\fP. The arguments can be after, before, or among the options.
.SS "options"
.PP
\fCoptions\fP is an array of option objects. Each option in the array can have the following fields. None are required, but you should at least provide a short or long name.
.RS
.nf
\fClet options = [
{ short : 'l',
long : 'list',
description : 'Show a list',
value : false, // default false
required : true, // default false
callback : function (value) { ... },
}, // ... followed by more options
];
\fP
.fi
.RE
.SS "arguments"
.PP
\fCarguments\fP require less configuration. This is an optional argument to \fCopts.parse\fP:
.RS
.nf
\fClet arguments =
{ name : 'script',
required : true, // not required by default
callback : function (value) { ... },
};
\fP
.fi
.RE
.SS "help text generator"
.PP
Finally, you can add an automatically generated help message by passing
a last parameter of \fItrue\fP. This is also an optional argument to \fCopts.parse\fP.
.RS
.nf
\fCopts.parse(options, true);
// or if you want more control, you can do:
/*
options.push({
long : 'help',
description : 'Show this help message',
callback : require('opts').help,
}
opts.parse(options);
*/
\fP
.fi
.RE
.SH "AUTHOR / CHANGELOG / LICENSE"
.PP
Email: ohkay@khtdr.com
.PP
Relatively unchanged since 2010.
.RE
See \fIhttps://github.com/khtdr/opts/blob/master/CHANGES.org\fP
.PP
BSD 2-Clause License
.RE
See \fIhttps://github.com/khtdr/opts/blob/master/LICENSE\fP