Skip to content

Commit 27ea56a

Browse files
committed
docs: update info
1 parent 7505b2b commit 27ea56a

File tree

1 file changed

+46
-31
lines changed

1 file changed

+46
-31
lines changed

README.md

+46-31
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,27 @@ npm i -D @hypernym/args
1616

1717
## Parser
1818

19-
### Commands
19+
### Arguments
2020

21-
Specifies _commands_ without a prefix.
21+
Unprefixed inputs are stored in an array.
2222

2323
```sh
24-
$ command
24+
$ arg
2525

26-
# => { _: ['command'] }
26+
# => { _: ['arg'] }
2727
```
2828

2929
```sh
30-
$ command-a command-b command-c
30+
$ arg-a arg-b arg-c
3131

32-
# => { _: ['command-a', 'command-b', 'command-c'] }
32+
# => { _: ['arg-a', 'arg-b', 'arg-c'] }
3333
```
3434

3535
### Flags
3636

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`.
3840

3941
```sh
4042
$ --flag
@@ -50,7 +52,9 @@ $ --flag value
5052

5153
### Aliases
5254

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`.
5458

5559
```sh
5660
$ -alias
@@ -66,8 +70,8 @@ $ -alias value
6670

6771
### Ignores
6872

69-
- Ignores args `--` and `-`
70-
- Ignores all args that include `=`
73+
- Ignores standalone inputs `--` and `-`
74+
- Ignores all inputs that include `=`
7175

7276
```sh
7377
$ --flag=value -- arg=value - -alias=value
@@ -77,49 +81,60 @@ $ --flag=value -- arg=value - -alias=value
7781

7882
## Usage
7983

80-
### Simple
81-
8284
```sh
83-
$
85+
$ hello world --foo bar -baz -cli demo --fuz
8486
```
8587

8688
```ts
8789
import { createArgs } from '@hypernym/args'
8890

89-
interface Args {}
91+
interface Args {
92+
foo?: string
93+
baz?: boolean
94+
cli?: string
95+
fuz?: boolean
96+
}
9097

9198
const args = createArgs<Args>()
9299

93100
console.log(args)
94101

95-
/*
96-
102+
/* Output:
103+
{
104+
_: ['hello', 'world'],
105+
foo: 'bar',
106+
baz: true,
107+
cli: 'demo',
108+
fuz: true
109+
}
97110
*/
98111
```
99112

100-
### Custom
113+
## Options
101114

102-
```sh
103-
$
104-
```
115+
### argv
116+
117+
- Type: `string[]`
118+
- Default: `process.argv.slice(2)`
105119

106120
```ts
107-
import { createArgs } from '@hypernym/args'
121+
const args = createArgs({
122+
argv: process.argv.slice(2),
123+
})
124+
```
125+
126+
### alias
108127

109-
interface Args {}
128+
- Type: `object`
129+
- Default: `undefined`
110130

111-
const args = createArgs<Args>({
131+
```ts
132+
const args = createArgs({
112133
alias: {
113-
alias: ['a', 'b'],
114-
command: 'cmd',
134+
config: ['conf', 'c'],
135+
help: 'h',
115136
},
116137
})
117-
118-
console.log(args)
119-
120-
/*
121-
122-
*/
123138
```
124139

125140
## Community

0 commit comments

Comments
 (0)