0.4.0 • Published 3 years ago

yargs-vc v0.4.0

Weekly downloads
7
License
Apache-2.0
Repository
-
Last release
3 years ago

yargs

yargs-vc, or a yargs ViewController, is just a logical class for organizing the information a yargs command would receive.

Install

npm install yargs-vc

Usage

View Controller

An example:

const YargsVC = require('yargs-vc');

class RegisterVC extends YargsVC {

  static command = 'example1';
  static description = 'Example command';

  async controller(argv) {

    if (argv.verbose) {
      console.log('Ran command in verbose mode.');
    }
  
  }

}

module.exports = RegisterVC;

Command parameters (yargs positionals)

const YargsVC = require('yargs-vc');

class RegisterVC extends YargsVC {

  static command = 'example2 [level]';
  static description = 'Example command';

  async controller(argv) {

    if (argv.verbose) {
      console.log('Ran command in verbose mode.');
    }

    if (argv.level) {
      console.log('Ran command with verbose level', argv.level);
    }
  
  }

  setup(yargs) {

    yargs
      .positional('level', {
        describe: 'What level of super verbosity you want',
        default: 1,
      });

  }

}

module.exports = RegisterVC;

Init yargs with ViewController

Just pass the ViewController to the init function and it will start yargs with the ViewController(s).

const init = require('yargs-vc/init');

const ExampleVC = require('./commands/example');

init([
  ExampleVC,
])
0.4.0

3 years ago

0.3.0

4 years ago

0.2.0

4 years ago

0.1.0

4 years ago