Vorpal CLI Framework

1.12.0 · maintenance · verified Sun Apr 19

Vorpal is a framework designed for building interactive command-line interface (CLI) applications in Node.js, positioning itself as an early pioneer in creating immersive CLI environments. It offers a comprehensive API for defining commands, handling arguments and options, enabling piped commands, providing persistent history, built-in help, and tab-completion. The framework is built upon and inspired by `commander.js` for its command structure and `inquirer.js` for interactive prompting, creating an isolated, shell-like experience. The current stable version, 1.12.0, was released some time ago, and the project is explicitly in an 'OPEN Open Source' state, actively seeking new maintainers, indicating a minimal or inactive release cadence from the original author. Its key differentiator is providing a full interactive shell within Node.js, facilitating complex, rich CLI applications through a simple API and extensibility.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates defining two commands: `greet` with an argument and an optional flag, and `add` with variadic arguments, then initializes the interactive CLI.

const vorpal = require('vorpal')();

vorpal
  .command('greet <name>', 'Greets the given name.')
  .option('-p, --polite', 'Use a polite greeting.')
  .action(function(args, callback) {
    const greeting = args.options.polite ? 'Hello there, ' : 'Hi, ';
    this.log(`${greeting}${args.name}!`)
    callback();
  });

vorpal
  .command('add <numbers...>', 'Adds a list of numbers.')
  .action(function(args, callback) {
    const sum = args.numbers.reduce((acc, num) => acc + parseFloat(num), 0);
    this.log(`The sum is: ${sum}`);
    callback();
  });

vorpal
  .delimiter('mycli$')
  .show();

view raw JSON →