Skip to content

Commit cedfabb

Browse files
committed
Added an Argument class.
1 parent b6bd583 commit cedfabb

File tree

4 files changed

+21
-10
lines changed

4 files changed

+21
-10
lines changed

src/Argument.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// @flow
2+
3+
export default class Argument {
4+
name: string;
5+
required: boolean;
6+
variadic: boolean;
7+
8+
constructor(name: string, required: boolean = false, variadic: boolean = false) {
9+
this.name = name;
10+
this.required = required;
11+
this.variadic = variadic;
12+
}
13+
}

src/Command.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// @flow
22

33
import EventEmitter from 'events';
4+
import Argument from './Argument';
45
import Option from './Option';
56
// import camelCase from './utils/camelCase';
67
import humanReadableArgName from './utils/humanReadableArgName';
@@ -9,7 +10,6 @@ import padRow from './utils/padRow';
910

1011
import type {
1112
ActionCallback,
12-
Argument,
1313
Autocomplete,
1414
CancelCallback,
1515
DoneCallback,
@@ -28,7 +28,7 @@ export default class Command extends EventEmitter {
2828
options: Option[];
2929
_allowUnknownOptions: boolean;
3030
_aliases: string[];
31-
_args: Argument[];
31+
_args: Argument[]; // TODO - Unprivate
3232
_autocomplete: ?Autocomplete;
3333
_cancel: ?CancelCallback;
3434
_catch: boolean;
@@ -384,7 +384,11 @@ export default class Command extends EventEmitter {
384384
}
385385

386386
if (argDetails.name) {
387-
this._args.push(argDetails);
387+
this._args.push(new Argument(
388+
argDetails.name,
389+
argDetails.required,
390+
argDetails.variadic,
391+
));
388392
}
389393
});
390394

src/types.js

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,6 @@ export type ActionCallback = (
1010
callback: (error: ?Error) => void,
1111
) => ?Promise<string>;
1212

13-
export type Argument = {
14-
name: string,
15-
required: boolean,
16-
variadic: boolean,
17-
};
18-
1913
export type Autocomplete =
2014
// Array of strings
2115
string[] |

src/utils/humanReadableArgName.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// @flow
22

3-
import type { Argument } from '../types';
3+
import type Argument from '../Argument';
44

55
/**
66
* Makes an argument name pretty for help.

0 commit comments

Comments
 (0)