Skip to content

Commit 6109a3e

Browse files
committed
docs: options
Signed-off-by: Lexus Drumgold <unicornware@flexdevelopment.llc>
1 parent 208eb04 commit 6109a3e

File tree

3 files changed

+45
-1
lines changed

3 files changed

+45
-1
lines changed

.vscode/settings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"rewrap.wrappingColumn": 130
2121
},
2222
"[markdown]": {
23+
"editor.defaultFormatter": "unifiedjs.vscode-remark",
2324
"editor.formatOnSave": true,
2425
"editor.rulers": [
2526
{

README.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
- [Install](#install)
2222
- [Use](#use)
2323
- [Creating a *program*](#creating-a-program)
24+
- [Options](#options)
2425
- [API](#api)
2526
- [`Argument(info)`](#argumentinfo)
2627
- [`Argument#choices([choices])`](#argumentchoiceschoices)
@@ -240,6 +241,48 @@ import { Command } from '@flex-development/kronk'
240241
const program: Command = new Command()
241242
```
242243

244+
### Options
245+
246+
Options are defined with the [`.option()`](#commandoptioninfo-data) and [`.options()`](#commandoptionsinfos) methods,
247+
which also serve as documentation for the options. Each option can have at most 2 flags, typically one long flag and one
248+
short or shortish (e.g. `--ws`) flag. Flags can be separated by commas (`,`), pipes (`|`), or spaces (` `).
249+
250+
An option and its option-argument can be separated by an equal sign (`=`) or spaces (` `).
251+
A short option (i.e. `-p`) and its option-argument can also be combined.
252+
253+
```sh
254+
serve --port 80
255+
serve --port=80
256+
serve -p 80
257+
serve -p80
258+
serve -p=80
259+
```
260+
261+
Options on the command line are not positional, and can be specified before or after command-arguments.
262+
263+
```sh
264+
serve --port=80 ./server.mts
265+
serve ./src/main.mts -p8080
266+
```
267+
268+
If a non-option (i.e. `-13`) looks like an option because it starts with a hyphen (`-`), a delimiter (`--`) can be used
269+
to demarcate the command-argument from an option.
270+
271+
```sh
272+
clamp -M3 -m-1 -- -13
273+
```
274+
275+
Parsed options can be accessed by calling [`.opts<T>()`](#commandoptst) on a [`Command`](#commandinfo) object, and are
276+
passed to the command's [`action`](#commandactionaction) handler.
277+
Multi-word options such as `--template-engine` are camelCased, becoming `program.opts().templateEngine`, or can be
278+
configured to be converted using snake\_case, becoming `program.opts().template_engine`.
279+
280+
There are additional, related routines for when `.opts<T>()` is not enough:
281+
282+
- [`.optionValue(key[, value][, source])`](#commandoptionvaluekey-value-source)
283+
- [`.optionValueSource(key[, source])`](#commandoptionvaluesourcekey-source)
284+
- [`.optsWithGlobals<T>()`](#commandoptswithglobalst)
285+
243286
## API
244287

245288
### `Argument(info)`

src/types/flags.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
* The flags string can contain at most 2 flags, typically one long flag and one
1010
* short or shortish (e.g. `--ws`) flag. Flags are separated by commas (`,`),
11-
* pipes (`|`), or spaces.
11+
* pipes (`|`), or spaces (` `).
1212
*
1313
* A short flag is a hyphen — specifically [HYPHEN-MINUS `U+002D`][hyphen] —
1414
* followed by one case-insensitive alphanumeric character.

0 commit comments

Comments
 (0)