Skip to content

Instantly share code, notes, and snippets.

@verchol
Created December 19, 2017 08:23
Show Gist options
  • Save verchol/d4ae35e37f43006076ae0ef8555b02db to your computer and use it in GitHub Desktop.
Save verchol/d4ae35e37f43006076ae0ef8555b02db to your computer and use it in GitHub Desktop.
const yargs = require('yargs');
const assert = require('assert');
const _ = require('lodash');
class TopCommand {
constructor(command){
this.command = command;
this.subCommands = [];
}
subCommand(command){
this.subCommands.push(command);
return this;
}
toCommand(){
let command = this.command;
assert(_.get(this.command, "builder", true));
let builder = (yargs)=>{
_.forEach(this.subCommands, (command)=>{
yargs.command(command);
})
}
command.builder = builder;
return command;
}
}
const run = new TopCommand({
command : "run",
desription : "top command run",
handler : ()=>{
console.log('run ->');
}
})
module.exports = run;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment