-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuickRef.txt
More file actions
63 lines (47 loc) · 1.74 KB
/
Copy pathQuickRef.txt
File metadata and controls
63 lines (47 loc) · 1.74 KB
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
fncli Quick Reference
import fncli from "fncli" // or require
fncli(async function main(arg, optarg="default"){
// This signature becomes usage: ...
})
It turns your `main()` into a CLI and `argv` into a function call.
Use destructuring for options:
async function main({v: verbose=false, port=8080}, ...rest){
// This signature becomes usage: ...
}
Multiple commands supported with an object:
fncli({
async login({prod=true}) {},
async logout() {}
})
POSITIONAL ARGUMENTS
name required positional arg
name = "x" optional positional with default
...names rest positional (zero or more)
OPTIONS
{flag = false} --flag boolean flag
{opt = "x"} --opt=<value> with default
{f: flag = false} -f / --flag (short alias)
COMMANDS
object of functions sub-commands (function names)
nested objects nested sub-commands
COMMENTS & HELP
// comment before params command synopsis
// comment after param per-arg/option description
ERROR HANDLING
return "error: ..." prints usage + error, exit code 1
throw "error: ..." prints usage + error, exit code 1
SPECIAL
async function awaited before exit
-- in argv stops option parsing
-h / --help added by default (help: true)
EXIT CODES
0 success
1 handler validation/exception
2 usage error (missing args, invalid options)
EXAMPLE WITH USAGE DESCRIPTIONS
function clone(
url, // Repository URL
{depth = undefined} // Shallow clone depth
) { /* ... */ }
fncli({ clone })
$ script clone https://github.com/user/repo --depth=1