You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: readme.md
+82-4Lines changed: 82 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -141,16 +141,94 @@ prog
141
141
```
142
142
143
143
144
+
## Single Command Mode
145
+
146
+
In certain circumstances, you may only need `sade` for a single-command CLI application.
147
+
148
+
> **Note:** Until `v1.6.0`, this made for an awkward pairing.
149
+
150
+
To enable this, you may make use of the [`isSingle`](#issingle) argument. Doing so allows you to pass the program's entire [`usage` text](#usage-1) into the `name` argument.
151
+
152
+
With "Single Command Mode" enabled, your entire binary operates as one command. This means that any [`prog.command`](#progcommandusage-desc-opts) calls are disallowed & will instead throw an Error. Of course, you may still define a program version, a description, an example or two, and declare options. You are customizing the program's attributes as a whole.<sup>*</sup>
153
+
154
+
> <sup>*</sup> This is true for multi-command applications, too, up until your first `prog.command()` call!
155
+
156
+
***Example***
157
+
158
+
Let's reconstruct [`sirv-cli`](https://github.com/lukeed/sirv), which is a single-command application that (optionally) accepts a directory from which to serve files. It also offers a slew of option flags:
159
+
160
+
```js
161
+
sade('sirv [dir]', true)
162
+
.version('1.0.0')
163
+
.describe('Run a static file server')
164
+
.example('public -qeim 31536000')
165
+
.example('--port 8080 --etag')
166
+
.example('my-app --dev')
167
+
.option('-D, --dev', 'Enable "dev" mode')
168
+
.option('-e, --etag', 'Enable "Etag" header')
169
+
// There are a lot...
170
+
.option('-H, --host', 'Hostname to bind', 'localhost')
171
+
.option('-p, --port', 'Port to bind', 5000)
172
+
.action((dir, opts) => {
173
+
// Program handler
174
+
})
175
+
.parse(process.argv);
176
+
```
177
+
178
+
When `sirv --help` is run, the generated help text is trimmed, fully aware that there's only one command in this program:
179
+
180
+
```
181
+
Description
182
+
Run a static file server
183
+
184
+
Usage
185
+
$ sirv [dir] [options]
186
+
187
+
Options
188
+
-D, --dev Enable "dev" mode
189
+
-e, --etag Enable "Etag" header
190
+
-H, --host Hostname to bind (default localhost)
191
+
-p, --port Port to bind (default 5000)
192
+
-v, --version Displays current version
193
+
-h, --help Displays this message
194
+
195
+
Examples
196
+
$ sirv public -qeim 31536000
197
+
$ sirv --port 8080 --etag
198
+
$ sirv my-app --dev
199
+
```
200
+
201
+
202
+
144
203
## API
145
204
146
-
### sade(name)
205
+
### sade(name, isSingle)
206
+
Returns: `Program`
207
+
208
+
Returns your chainable Sade instance, aka your `Program`.
147
209
148
210
#### name
149
-
150
211
Type: `String`<br>
151
-
Returns: `Program`
212
+
Required: `true`
213
+
214
+
The name of your `Program` / binary application.
215
+
216
+
#### isSingle
217
+
Type: `Boolean`<br>
218
+
Default: `name.includes(' ');`
219
+
220
+
If your `Program` is meant to have ***only one command***.<br>
221
+
When `true`, this simplifies your generated `--help` output such that:
222
+
223
+
* the "root-level help" is your _only_ help text
224
+
* the "root-level help" does not display an `Available Commands` section
225
+
* the "root-level help" does not inject `$ name <command>` into the `Usage` section
226
+
* the "root-level help" does not display `For more info, run any command with the `--help` flag` text
227
+
228
+
You may customize the `Usage` of your command by modifying the `name` argument directly.<br>
229
+
Please read [Single Command Mode](#single-command-mode) for an example and more information.
152
230
153
-
The name of your bin/program. Returns the `Program` itself, wherein all other methods are available.
231
+
> **Important:** Whenever `name` includes a custom usage, then `isSingle` is automatically assumed and enforced!
0 commit comments