Skip to content

Commit 6df3141

Browse files
authored
Update all deps, run Prettier. (#58)
1 parent 99b578e commit 6df3141

File tree

6 files changed

+423
-205
lines changed

6 files changed

+423
-205
lines changed

LICENSE.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
MIT License
1+
The MIT License (MIT)
22

3-
Copyright (c) 2017-2019 Zeit, Inc.
4-
Copyright (c) 2020 Vercel, Inc.
3+
Copyright (c) 2021 Vercel, Inc.
54

65
Permission is hereby granted, free of charge, to any person obtaining a copy
76
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 71 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,11 @@
1-
# Arg [![CircleCI](https://circleci.com/gh/vercel/arg.svg?style=svg)](https://circleci.com/gh/vercel/arg)
1+
# Arg
22

33
`arg` is an unopinionated, no-frills CLI argument parser.
44

55
## Installation
66

7-
Use Yarn or NPM to install.
8-
9-
```console
10-
$ yarn add arg
11-
```
12-
13-
or
14-
15-
```console
16-
$ npm install arg
7+
```bash
8+
npm install arg
179
```
1810

1911
## Usage
@@ -35,7 +27,10 @@ in which case an empty array is returned).
3527
const arg = require('arg');
3628

3729
// `options` is an optional parameter
38-
const args = arg(spec, options = {permissive: false, argv: process.argv.slice(2)});
30+
const args = arg(
31+
spec,
32+
(options = { permissive: false, argv: process.argv.slice(2) })
33+
);
3934
```
4035

4136
For example:
@@ -50,18 +45,18 @@ const arg = require('arg');
5045

5146
const args = arg({
5247
// Types
53-
'--help': Boolean,
48+
'--help': Boolean,
5449
'--version': Boolean,
55-
'--verbose': arg.COUNT, // Counts the number of times --verbose is passed
56-
'--port': Number, // --port <number> or --port=<number>
57-
'--name': String, // --name <string> or --name=<string>
58-
'--tag': [String], // --tag <string> or --tag=<string>
50+
'--verbose': arg.COUNT, // Counts the number of times --verbose is passed
51+
'--port': Number, // --port <number> or --port=<number>
52+
'--name': String, // --name <string> or --name=<string>
53+
'--tag': [String], // --tag <string> or --tag=<string>
5954

6055
// Aliases
61-
'-v': '--verbose',
62-
'-n': '--name', // -n <string>; result is stored in --name
63-
'--label': '--name' // --label <string> or --label=<string>;
64-
// result is stored in --name
56+
'-v': '--verbose',
57+
'-n': '--name', // -n <string>; result is stored in --name
58+
'--label': '--name' // --label <string> or --label=<string>;
59+
// result is stored in --name
6560
});
6661

6762
console.log(args);
@@ -104,19 +99,32 @@ For custom handlers that wish to behave as flags, you may pass the function thro
10499
```javascript
105100
const arg = require('arg');
106101

107-
const argv = ['--foo', 'bar', '-ff', 'baz', '--foo', '--foo', 'qux', '-fff', 'qix'];
102+
const argv = [
103+
'--foo',
104+
'bar',
105+
'-ff',
106+
'baz',
107+
'--foo',
108+
'--foo',
109+
'qux',
110+
'-fff',
111+
'qix'
112+
];
108113

109114
function myHandler(value, argName, previousValue) {
110115
/* `value` is always `true` */
111116
return 'na ' + (previousValue || 'batman!');
112117
}
113118

114-
const args = arg({
115-
'--foo': arg.flag(myHandler),
116-
'-f': '--foo'
117-
}, {
118-
argv
119-
});
119+
const args = arg(
120+
{
121+
'--foo': arg.flag(myHandler),
122+
'-f': '--foo'
123+
},
124+
{
125+
argv
126+
}
127+
);
120128

121129
console.log(args);
122130
/*
@@ -136,12 +144,15 @@ const arg = require('arg');
136144

137145
const argv = ['-AAAA', '-BBBB'];
138146

139-
const args = arg({
140-
'-A': arg.COUNT,
141-
'-B': [Boolean]
142-
}, {
143-
argv
144-
});
147+
const args = arg(
148+
{
149+
'-A': arg.COUNT,
150+
'-B': [Boolean]
151+
},
152+
{
153+
argv
154+
}
155+
);
145156

146157
console.log(args);
147158
/*
@@ -168,7 +179,8 @@ For example:
168179
const args = arg(
169180
{
170181
'--foo': String
171-
}, {
182+
},
183+
{
172184
argv: ['hello', '--foo', 'world']
173185
}
174186
);
@@ -194,13 +206,22 @@ For example:
194206
```javascript
195207
const arg = require('arg');
196208

197-
const argv = ['--foo', 'hello', '--qux', 'qix', '--bar', '12345', 'hello again'];
209+
const argv = [
210+
'--foo',
211+
'hello',
212+
'--qux',
213+
'qix',
214+
'--bar',
215+
'12345',
216+
'hello again'
217+
];
198218

199219
const args = arg(
200220
{
201221
'--foo': String,
202222
'--bar': Number
203-
}, {
223+
},
224+
{
204225
argv,
205226
permissive: true
206227
}
@@ -211,10 +232,10 @@ results in:
211232

212233
```javascript
213234
const args = {
214-
_: ['--qux', 'qix', 'hello again'],
215-
'--foo': 'hello',
216-
'--bar': 12345
217-
}
235+
_: ['--qux', 'qix', 'hello again'],
236+
'--foo': 'hello',
237+
'--bar': 12345
238+
};
218239
```
219240

220241
#### `stopAtPositional`
@@ -233,7 +254,8 @@ const args = arg(
233254
{
234255
'--foo': Boolean,
235256
'--bar': Boolean
236-
}, {
257+
},
258+
{
237259
argv,
238260
stopAtPositional: true
239261
}
@@ -257,16 +279,17 @@ differentiate between user error and developer error (bug).
257279
##### ARG_UNKNOWN_OPTION
258280

259281
If an unknown option (not defined in the spec object) is passed, an error with code `ARG_UNKNOWN_OPTION` will be thrown:
282+
260283
```js
261284
// cli.js
262285
try {
263-
require('arg')({ '--hi': String });
286+
require('arg')({ '--hi': String });
264287
} catch (err) {
265-
if (err.code === 'ARG_UNKNOWN_OPTION') {
266-
console.log(err.message);
267-
} else {
268-
throw err;
269-
}
288+
if (err.code === 'ARG_UNKNOWN_OPTION') {
289+
console.log(err.message);
290+
} else {
291+
throw err;
292+
}
270293
}
271294
```
272295

@@ -291,7 +314,4 @@ if (!args['--name']) throw new Error('missing required argument: --name');
291314

292315
# License
293316

294-
Copyright &copy; 2017-2019 by ZEIT, Inc.
295-
Copyright &copy; 2020 by Vercel, Inc.
296-
297317
Released under the [MIT License](LICENSE.md).

index.d.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
11
declare const flagSymbol: unique symbol;
22

3-
declare function arg<T extends arg.Spec>(spec: T, options?: arg.Options): arg.Result<T>;
3+
declare function arg<T extends arg.Spec>(
4+
spec: T,
5+
options?: arg.Options
6+
): arg.Result<T>;
47

58
declare namespace arg {
69
export function flag<T>(fn: T): T & { [flagSymbol]: true };
710

811
export const COUNT: Handler<number> & { [flagSymbol]: true };
912

10-
export type Handler <T = any> = (value: string, name: string, previousValue?: T) => T;
13+
export type Handler<T = any> = (
14+
value: string,
15+
name: string,
16+
previousValue?: T
17+
) => T;
1118

1219
export class ArgError extends Error {
1320
constructor(message: string, code: string);
@@ -24,7 +31,7 @@ declare namespace arg {
2431
? ReturnType<T[K]>
2532
: T[K] extends [Handler]
2633
? Array<ReturnType<T[K][0]>>
27-
: never
34+
: never;
2835
};
2936

3037
export interface Options {

0 commit comments

Comments
 (0)