Skip to content

Commit

Permalink
Added an Argument class.
Browse files Browse the repository at this point in the history
  • Loading branch information
milesj committed Jul 18, 2017
1 parent b6bd583 commit cedfabb
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 10 deletions.
13 changes: 13 additions & 0 deletions src/Argument.js
Original file line number Diff line number Diff line change
@@ -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;
}
}
10 changes: 7 additions & 3 deletions src/Command.js
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -9,7 +10,6 @@ import padRow from './utils/padRow';

import type {
ActionCallback,
Argument,
Autocomplete,
CancelCallback,
DoneCallback,
Expand All @@ -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;
Expand Down Expand Up @@ -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,
));
}
});

Expand Down
6 changes: 0 additions & 6 deletions src/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@ export type ActionCallback = (
callback: (error: ?Error) => void,
) => ?Promise<string>;

export type Argument = {
name: string,
required: boolean,
variadic: boolean,
};

export type Autocomplete =
// Array of strings
string[] |
Expand Down
2 changes: 1 addition & 1 deletion src/utils/humanReadableArgName.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @flow

import type { Argument } from '../types';
import type Argument from '../Argument';

/**
* Makes an argument name pretty for help.
Expand Down

0 comments on commit cedfabb

Please sign in to comment.