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("", "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);