Created
December 19, 2017 08:23
-
-
Save verchol/d4ae35e37f43006076ae0ef8555b02db to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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