docs
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Tj Holowaychuk · committed by Tj Holowaychuk · parent 46be01f · Browse files · 2 files·+52 added−3 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
2 files+52 added−3 removed
- other:+52 added−3 removed
Provenance
- Commit
03178dc- Tree
71da8ee- Author
Tj Holowaychuk <tj@vision-media.ca>- Committer
Tj Holowaychuk <tj@vision-media.ca>- Parent
46be01f
2 files changed+52 added−3 removed
modified:examples/deploy+1 added-1 removed
11 unmodified lines12 .option('-c, --config <path>', 'set config path. defaults to ./deploy.conf')13 .option('-T, --no-tests', 'ignore test hook')14 15 program16- .command('setup [env]')16+ .command('setup')17 .description('run remote setup commands')18 .action(function(){19 console.log('setup');20 });18 unmodified linesmodified:lib/commander.js+51 added-2 removed
94 unmodified lines95 */96 97 Command.prototype.__proto__ = EventEmitter.prototype;98 99+/**100+ * Add command `name`.101+ *102+ * Examples:103+ *104+ * program105+ * .version('0.0.1')106+ * .option('-C, --chdir <path>', 'change the working directory')107+ * .option('-c, --config <path>', 'set config path. defaults to ./deploy.conf')108+ * .option('-T, --no-tests', 'ignore test hook')109+ * 110+ * program111+ * .command('setup')112+ * .description('run remote setup commands')113+ * .action(function(){114+ * console.log('setup');115+ * });116+ * 117+ * program118+ * .command('exec <cmd>')119+ * .description('run the given remote command')120+ * .action(function(cmd){121+ * console.log('exec "%s"', cmd);122+ * });123+ * 124+ * program125+ * .command('*')126+ * .description('deploy the given env')127+ * .action(function(env){128+ * console.log('deploying "%s"', env);129+ * });130+ * 131+ * program.parse(process.argv);132+ *133+ * @param {String} name134+ * @return {Command} the new command135+ * @api public136+ */137+138 Command.prototype.command = function(name){139 var args = name.split(/ +/);140 var cmd = new Command(args.shift());141 this.commands.push(cmd);103- cmd.arg(args);142+ cmd.parseExpectedArgs(args);143 cmd.parent = this;144 return cmd;145 };146 147+/**148+ * Parse expected `args`.149+ *150+ * For example `["[type]"]` becomes `[{ required: false, name: 'type' }]`.151+ *152+ * @param {Array} args153+ * @return {Command} for chaining154+ * @api public155+ */156+108-Command.prototype.arg = function(args){157+Command.prototype.parseExpectedArgs = function(args){158 if (!args.length) return;159 var self = this;160 args.forEach(function(arg){161 switch (arg[0]) {325 unmodified lines