@@ -16,25 +16,27 @@ npm i -D @hypernym/args
16
16
17
17
## Parser
18
18
19
- ### Commands
19
+ ### Arguments
20
20
21
- Specifies _ commands _ without a prefix .
21
+ Unprefixed inputs are stored in an array .
22
22
23
23
``` sh
24
- $ command
24
+ $ arg
25
25
26
- # => { _: ['command '] }
26
+ # => { _: ['arg '] }
27
27
```
28
28
29
29
``` sh
30
- $ command -a command -b command -c
30
+ $ arg -a arg -b arg -c
31
31
32
- # => { _: ['command -a', 'command -b', 'command -c'] }
32
+ # => { _: ['arg -a', 'arg -b', 'arg -c'] }
33
33
```
34
34
35
35
### Flags
36
36
37
- Specifies _ flags_ with the ` -- ` prefix.
37
+ Inputs with ` -- ` prefix are parsed as _ flags_ .
38
+
39
+ By default, standalone flags with no value are defined as ` true ` .
38
40
39
41
``` sh
40
42
$ --flag
@@ -50,7 +52,9 @@ $ --flag value
50
52
51
53
### Aliases
52
54
53
- Specifies _ aliases_ with the ` - ` prefix.
55
+ Inputs with ` - ` prefix are parsed as _ aliases_ .
56
+
57
+ By default, standalone aliases with no value are defined as ` true ` .
54
58
55
59
``` sh
56
60
$ -alias
@@ -66,8 +70,8 @@ $ -alias value
66
70
67
71
### Ignores
68
72
69
- - Ignores args ` -- ` and ` - `
70
- - Ignores all args that include ` = `
73
+ - Ignores standalone inputs ` -- ` and ` - `
74
+ - Ignores all inputs that include ` = `
71
75
72
76
``` sh
73
77
$ --flag=value -- arg=value - -alias=value
@@ -77,49 +81,60 @@ $ --flag=value -- arg=value - -alias=value
77
81
78
82
## Usage
79
83
80
- ### Simple
81
-
82
84
``` sh
83
- $
85
+ $ hello world --foo bar -baz -cli demo --fuz
84
86
```
85
87
86
88
``` ts
87
89
import { createArgs } from ' @hypernym/args'
88
90
89
- interface Args {}
91
+ interface Args {
92
+ foo? : string
93
+ baz? : boolean
94
+ cli? : string
95
+ fuz? : boolean
96
+ }
90
97
91
98
const args = createArgs <Args >()
92
99
93
100
console .log (args )
94
101
95
- /*
96
-
102
+ /* Output:
103
+ {
104
+ _: ['hello', 'world'],
105
+ foo: 'bar',
106
+ baz: true,
107
+ cli: 'demo',
108
+ fuz: true
109
+ }
97
110
*/
98
111
```
99
112
100
- ### Custom
113
+ ## Options
101
114
102
- ``` sh
103
- $
104
- ```
115
+ ### argv
116
+
117
+ - Type: ` string[] `
118
+ - Default: ` process.argv.slice(2) `
105
119
106
120
``` ts
107
- import { createArgs } from ' @hypernym/args'
121
+ const args = createArgs ({
122
+ argv: process .argv .slice (2 ),
123
+ })
124
+ ```
125
+
126
+ ### alias
108
127
109
- interface Args {}
128
+ - Type: ` object `
129
+ - Default: ` undefined `
110
130
111
- const args = createArgs <Args >({
131
+ ``` ts
132
+ const args = createArgs ({
112
133
alias: {
113
- alias : [' a ' , ' b ' ],
114
- command : ' cmd ' ,
134
+ config : [' conf ' , ' c ' ],
135
+ help : ' h ' ,
115
136
},
116
137
})
117
-
118
- console .log (args )
119
-
120
- /*
121
-
122
- */
123
138
```
124
139
125
140
## Community
0 commit comments