From cedfabb35374af92f956de74dfd603a817663f85 Mon Sep 17 00:00:00 2001 From: Miles Johnson Date: Tue, 18 Jul 2017 00:25:13 -0700 Subject: [PATCH] Added an Argument class. --- src/Argument.js | 13 +++++++++++++ src/Command.js | 10 +++++++--- src/types.js | 6 ------ src/utils/humanReadableArgName.js | 2 +- 4 files changed, 21 insertions(+), 10 deletions(-) create mode 100644 src/Argument.js diff --git a/src/Argument.js b/src/Argument.js new file mode 100644 index 00000000..37cd100d --- /dev/null +++ b/src/Argument.js @@ -0,0 +1,13 @@ +// @flow + +export default class Argument { + name: string; + required: boolean; + variadic: boolean; + + constructor(name: string, required: boolean = false, variadic: boolean = false) { + this.name = name; + this.required = required; + this.variadic = variadic; + } +} diff --git a/src/Command.js b/src/Command.js index d35c7ec7..ed21f3d5 100755 --- a/src/Command.js +++ b/src/Command.js @@ -1,6 +1,7 @@ // @flow import EventEmitter from 'events'; +import Argument from './Argument'; import Option from './Option'; // import camelCase from './utils/camelCase'; import humanReadableArgName from './utils/humanReadableArgName'; @@ -9,7 +10,6 @@ import padRow from './utils/padRow'; import type { ActionCallback, - Argument, Autocomplete, CancelCallback, DoneCallback, @@ -28,7 +28,7 @@ export default class Command extends EventEmitter { options: Option[]; _allowUnknownOptions: boolean; _aliases: string[]; - _args: Argument[]; + _args: Argument[]; // TODO - Unprivate _autocomplete: ?Autocomplete; _cancel: ?CancelCallback; _catch: boolean; @@ -384,7 +384,11 @@ export default class Command extends EventEmitter { } if (argDetails.name) { - this._args.push(argDetails); + this._args.push(new Argument( + argDetails.name, + argDetails.required, + argDetails.variadic, + )); } }); diff --git a/src/types.js b/src/types.js index aafdba3a..bcd0d15b 100644 --- a/src/types.js +++ b/src/types.js @@ -10,12 +10,6 @@ export type ActionCallback = ( callback: (error: ?Error) => void, ) => ?Promise; -export type Argument = { - name: string, - required: boolean, - variadic: boolean, -}; - export type Autocomplete = // Array of strings string[] | diff --git a/src/utils/humanReadableArgName.js b/src/utils/humanReadableArgName.js index 70e19e03..a4fc5bb6 100644 --- a/src/utils/humanReadableArgName.js +++ b/src/utils/humanReadableArgName.js @@ -1,6 +1,6 @@ // @flow -import type { Argument } from '../types'; +import type Argument from '../Argument'; /** * Makes an argument name pretty for help.