@beast-oe/cli-base
Beast CLI Manager Tool
Last updated a year ago by cosmin.ichim .
MIT · Repository · Original npm · Tarball · package.json
$ cnpm install @beast-oe/cli-base 
SYNC missed versions from official npm registry.

Beast CLI Framework

Beast CLI Framework repository for building command line applications.

Extra Information

Extra information about the various files available in the library.

Installation steps

Add cli-base library as a dependency:

  $npm install cli-base

Usage Example

Define a command by extending CommandBase class as below:

const CommandBase = require("cli-base");

class SampleCommand extends CommandBase {
  /**
   * Constructor of the comand.
   */
  constructor() {
    super("validate", "Validate application configuration file");
    
    // specify comand arguments with description and validator
    this._argument("<file>", "application.json file path", /^(.*)[\\/]application.json$/);

    // specify command options
    this._option(
      "--xml",
      "Outputs the result in xml format.",
      Boolean
    );
    this._option(
      "--json",
      "Outputs the result in json format.",
      Boolean
    );
    this._option(
      "--txt",
      "Outputs the result in string file format.",
      Boolean
    );
  }

  /**
   * Runs the command code.
   *
   * @param {Object} args The arguments of the command.
   * @param {Object} options The options of the command.
   * @param {Object} logger The logger.
   */
  async run(args, options, logger) {

    // add in here the command action

  }
}

Use CLIManager class to register defined commands, parse and run input commands.

const CLIManager = require("cli-base");
const application = require("../package.json");
const SampleCommand = require("./commands/SampleCommand");

const cliManager = new CLIManager(application.version, application.description);
// register SampleCommand
cliManager.registerCommand(new SampleCommand());

cliManager.parse(process.argv);

Current Tags

  • 1.0.0-beta.2                                ...           latest (a year ago)

3 Versions

  • 1.0.0-beta.2                                ...           a year ago
  • 1.0.0-beta.1                                ...           a year ago
  • 1.0.0-beta                                ...           a year ago
Downloads
Today 0
This Week 0
This Month 3
Last Day 0
Last Week 3
Last Month 0
Dependencies (6)
Dev Dependencies (12)
Dependents (1)

Copyright 2014 - 2017 © taobao.org |