dthree / vorpal

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

Support for version task by default #161

Open alansouzati opened 8 years ago

alansouzati commented 8 years ago

Currently I have a built-in node CLI for Grommet.

I'm in the process of investigating a framework to handle the CLI for me. I've compared multiple frameworks and yours is the one I liked the most API-wise. Good job!

Our CLI today has a grommet --version. I was wondering if you have something similar that would output the version of the CLI. For now, this is what I did, but I believe this task is generic enough that could be added be default as we have help and exit.

#!/usr/bin/env node
import vorpal from 'vorpal';
import path from 'path';

const cli = vorpal();
const cliPath = path.join(__dirname, '..');
const packageJSON = require(path.join(cliPath, 'package.json'));

cli
  .command('version')
  .action((args, cb) => {
    cli.log(packageJSON.version);
    cb();
  });

cli
  .delimiter(cli.chalk.magenta('grommet~$'))
  .show();

I would be happy to create a PR if you think that this is useful.

alansouzati commented 8 years ago

FYI, I know we could use NPM itself to handle that, but as you can see here, it is kind of weird the way they do it:

http://stackoverflow.com/questions/10972176/find-the-version-of-an-installed-npm-package

dthree commented 8 years ago

Hey thanks!

That's a good idea. You should write and publish Vorpal extension that does that - I think people would find that very useful! You could call it vorpal-version. It would be implemented like this:

const vorpal = new Vorpal();
vorpal.use(require('vorpal-version')
  .show();

This would simply run the above code sample you wrote and inject a new version command into Vorpal.

Here are the docs on writing extensions, and here are some sample extensions.

Let me know if you need any help!

alansouzati commented 8 years ago

Thanks, i think i got it. i will write a PR for that early next week.