dthree / vorpal

Node's framework for interactive CLIs
http://vorpal.js.org
MIT License
5.64k stars 280 forks source link

Command.chain / Command.bind / Command.use #198

Open ccorcos opened 7 years ago

ccorcos commented 7 years ago

I'd like to request a simple feature that will make Vorpal a bit more composable.

const pizzaOptions = vorpal => 
    vorpal
       .option('-p, --pepperoni', 'pepperoni topping')
       .option('-o, --olive', 'olive topping')

vorpal
  .command('pizza')
  .use(pizzaOptions)
  .action( /* ... */ )

It's effectively a monadic bind.

LongLiveCHIEF commented 7 years ago

What if the command instance could be treated like an array? You could use command.push(pizzaoptions) instead?

ccorcos commented 7 years ago

That works too, but use would be more generic / extensible. It would be used for not just options but anything :)