Convert Figma logo to code with AI

dthree logovorpal

Node's framework for interactive CLIs

5,642
280
5,642
139

Top Related Projects

A collection of common interactive command line user interfaces.

node.js command-line interfaces made easy

11,076

yargs the modern, pirate-themed successor to optimist.

8,977

CLI for generating, building, and releasing oclif CLIs. Built by Salesforce.

2,951

A delightful toolkit for building TypeScript-powered command-line apps.

Python Fire is a library for automatically generating command line interfaces (CLIs) from absolutely any Python object.

Quick Overview

Vorpal is a Node.js framework for building interactive command-line applications. It provides a powerful set of tools for creating complex CLIs with support for commands, options, arguments, and prompts, making it easier to develop feature-rich command-line interfaces.

Pros

  • Easy to use and intuitive API for creating CLI applications
  • Extensive features including command autocompletion, help generation, and command validation
  • Supports both synchronous and asynchronous command execution
  • Highly extensible through plugins and middleware

Cons

  • Limited to Node.js environments, not suitable for other programming languages
  • May be overkill for simple CLI applications with few commands
  • Learning curve for more advanced features and customizations
  • Less active development in recent years compared to some alternatives

Code Examples

  1. Creating a basic CLI application:
const vorpal = require('vorpal')();

vorpal
  .command('hello <name>')
  .description('Say hello to someone')
  .action(function(args) {
    this.log(`Hello, ${args.name}!`);
  });

vorpal
  .delimiter('mycli$')
  .show();
  1. Adding options to a command:
vorpal
  .command('greet <name>')
  .option('-l, --loud', 'Greet loudly')
  .action(function(args, callback) {
    const greeting = args.options.loud ? 'HELLO' : 'Hello';
    this.log(`${greeting}, ${args.name}!`);
    callback();
  });
  1. Using prompts for user input:
vorpal
  .command('ask')
  .action(function(args, callback) {
    this.prompt({
      type: 'input',
      name: 'name',
      message: 'What is your name?'
    }, function(result) {
      this.log(`Nice to meet you, ${result.name}!`);
      callback();
    });
  });

Getting Started

To get started with Vorpal, follow these steps:

  1. Install Vorpal in your project:

    npm install vorpal
    
  2. Create a new JavaScript file (e.g., cli.js) and add the following code:

    const vorpal = require('vorpal')();
    
    vorpal
      .command('hello')
      .description('Say hello')
      .action(function() {
        this.log('Hello, World!');
      });
    
    vorpal
      .delimiter('mycli$')
      .show();
    
  3. Run your CLI application:

    node cli.js
    

This will start an interactive CLI where you can type hello to see the greeting.

Competitor Comparisons

A collection of common interactive command line user interfaces.

Pros of Inquirer.js

  • Focused on user input prompts, making it simpler for specific use cases
  • Extensive range of prompt types (e.g., checkbox, password, editor)
  • Easier to integrate into existing Node.js applications

Cons of Inquirer.js

  • Limited to command-line input/output interactions
  • Lacks built-in command parsing and routing capabilities
  • Not designed for creating full-fledged CLI applications

Code Comparison

Inquirer.js example:

const inquirer = require('inquirer');

inquirer.prompt([
  { type: 'input', name: 'name', message: 'What is your name?' },
  { type: 'list', name: 'color', message: 'Favorite color?', choices: ['Red', 'Blue', 'Green'] }
]).then(answers => console.log(answers));

Vorpal example:

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

vorpal
  .command('greet <name>')
  .option('-c, --color <color>', 'Favorite color')
  .action(function(args, callback) {
    this.log(`Hello, ${args.name}! Your favorite color is ${args.options.color || 'unknown'}.`);
    callback();
  });

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

Summary

Inquirer.js excels at gathering user input through various prompt types, making it ideal for simple interactions. Vorpal, on the other hand, provides a more comprehensive framework for building interactive CLI applications with command parsing and routing. Choose Inquirer.js for straightforward input collection, and Vorpal for more complex CLI tools.

node.js command-line interfaces made easy

Pros of Commander.js

  • Lightweight and simple to use
  • Extensive documentation and large community support
  • Flexible and customizable command-line parsing

Cons of Commander.js

  • Less feature-rich compared to Vorpal
  • Lacks built-in interactive prompt functionality
  • No support for auto-completion out of the box

Code Comparison

Commander.js:

const program = require('commander');

program
  .version('0.1.0')
  .option('-p, --peppers', 'Add peppers')
  .option('-c, --cheese <type>', 'Add cheese')
  .parse(process.argv);

Vorpal:

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

vorpal
  .command('order pizza')
  .option('-p, --peppers', 'Add peppers')
  .option('-c, --cheese <type>', 'Add cheese')
  .action(function(args, callback) {
    // Action logic here
  });

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

Commander.js focuses on parsing command-line arguments and options, while Vorpal provides a more interactive CLI experience with built-in prompts and auto-completion. Commander.js is simpler and more lightweight, making it ideal for basic CLI applications. Vorpal, on the other hand, offers a richer set of features for creating complex, interactive command-line interfaces.

11,076

yargs the modern, pirate-themed successor to optimist.

Pros of yargs

  • More popular and widely adopted, with a larger community and ecosystem
  • Offers a more extensive set of features for complex command-line parsing
  • Better suited for building traditional CLI applications with multiple commands

Cons of yargs

  • Steeper learning curve due to its extensive API and configuration options
  • Can be overkill for simple CLI applications with minimal argument parsing needs

Code Comparison

yargs:

const argv = require('yargs')
  .option('name', {
    alias: 'n',
    describe: 'Your name'
  })
  .demandOption(['name'])
  .argv

console.log(`Hello, ${argv.name}!`)

Vorpal:

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

vorpal
  .command('greet <name>', 'Greet a person')
  .action(function(args, callback) {
    this.log(`Hello, ${args.name}!`);
    callback();
  });

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

Key Differences

  • Vorpal focuses on interactive command-line applications, while yargs is primarily for traditional CLI tools
  • Yargs provides more robust argument parsing and validation out of the box
  • Vorpal offers built-in support for command history, auto-completion, and a more interactive user experience

Use Cases

  • Choose yargs for complex CLI applications with multiple commands and options
  • Opt for Vorpal when building interactive, REPL-like command-line interfaces
8,977

CLI for generating, building, and releasing oclif CLIs. Built by Salesforce.

Pros of oclif

  • Built-in support for TypeScript, making it easier to develop and maintain large CLI applications
  • Extensive plugin system allowing for modular and extensible CLI development
  • Automatic generation of documentation and help text

Cons of oclif

  • Steeper learning curve due to its more complex architecture
  • Heavier footprint and potentially slower startup time for simpler CLI applications

Code Comparison

oclif:

import {Command, flags} from '@oclif/command'

export default class Hello extends Command {
  static description = 'Say hello'
  static flags = {
    name: flags.string({char: 'n', description: 'name to say hello to'})
  }
  async run() {
    const {flags} = this.parse(Hello)
    console.log(`Hello ${flags.name || 'world'}!`)
  }
}

Vorpal:

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

vorpal
  .command('hello [name]')
  .description('Say hello')
  .action(function(args, callback) {
    this.log(`Hello ${args.name || 'world'}!`);
    callback();
  });

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

Both oclif and Vorpal are powerful tools for building command-line interfaces in JavaScript. oclif offers a more structured approach with built-in TypeScript support and extensive plugins, making it suitable for larger, more complex CLI applications. Vorpal, on the other hand, provides a simpler, more lightweight solution that may be preferable for smaller projects or those requiring a lower learning curve.

2,951

A delightful toolkit for building TypeScript-powered command-line apps.

Pros of Gluegun

  • More active development and maintenance
  • Broader feature set, including file system operations and API integrations
  • Better TypeScript support and tooling

Cons of Gluegun

  • Steeper learning curve due to more complex architecture
  • Larger package size and potential overhead for simpler CLI applications
  • Less focus on interactive prompts compared to Vorpal

Code Comparison

Vorpal:

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

vorpal
  .command('hello <name>')
  .action(function(args, callback) {
    this.log(`Hello, ${args.name}!`);
    callback();
  });

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

Gluegun:

const { build } = require('gluegun');

const cli = build()
  .src(__dirname)
  .create();

cli.command('hello', {
  run: async (toolbox) => {
    const { print, parameters } = toolbox;
    print.info(`Hello, ${parameters.first}!`);
  }
});

cli.run();

Both Vorpal and Gluegun are powerful CLI development tools, but they cater to different needs. Vorpal excels in creating interactive command-line applications with a focus on simplicity, while Gluegun offers a more comprehensive toolkit for building complex CLI tools with additional features and better TypeScript integration.

Python Fire is a library for automatically generating command line interfaces (CLIs) from absolutely any Python object.

Pros of Python-Fire

  • Simpler syntax and less boilerplate code required
  • Automatically generates CLI interfaces from existing Python functions and classes
  • Supports a wider range of Python objects (classes, modules, objects)

Cons of Python-Fire

  • Less control over command-line argument parsing and validation
  • Fewer built-in features for interactive CLI experiences (e.g., prompts, progress bars)
  • Documentation generation is not as comprehensive as Vorpal's

Code Comparison

Python-Fire:

import fire

def hello(name="World"):
    return f"Hello {name}!"

if __name__ == '__main__':
    fire.Fire(hello)

Vorpal:

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

vorpal
  .command('hello [name]')
  .description('Say hello')
  .action(function(args, callback) {
    this.log(`Hello ${args.name || 'World'}!`);
    callback();
  });

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

Python-Fire offers a more concise approach, automatically generating CLI interfaces from existing functions. Vorpal provides more explicit control over command definitions and interactions but requires more setup code.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Vorpal

Build Status NPM Downloads Package Quality NPM Version XO code style

Conquer the command-line.

              (O)
              <M
   o          <M
  /| ......  /:M\------------------------------------------------,,,,,,
(O)[ vorpal ]::@+}==========================================------------>
  \| ^^^^^^  \:W/------------------------------------------------''''''
   o          <W
              <W
              (O)

Vorpal is Node's first framework for building interactive CLI applications. With a simple and powerful API, Vorpal opens the door to a new breed of rich, immersive CLI environments like cash and wat.

Notice

This is now an OPEN Open Source project. I am not able to invest a significant amount of time into maintaining Vorpal and so am looking for volunteers who would like to be active maintainers of the project. If you are interested, shoot me a note.

Contents

Introduction

Inspired by and based on commander.js, Vorpal is a framework for building immersive CLI applications built on an interactive prompt provided by inquirer.js. Vorpal launches Node into an isolated CLI environment and provides a suite of API commands and functionality including:

  • Simple, powerful command creation
  • Supports optional, required and variadic arguments and options
  • Piped commands
  • Persistent command history
  • Built-in help
  • Built-in tabbed auto-completion
  • Command-specific auto-completion
  • Customizable prompts
  • Extensive terminal control
  • Custom event listeners
  • And more

Vorpal supports community extensions, which empower it to do awesome things such as piping commands to less, importing commands live or supporting a built-in REPL.

Made with :heart: by dthree.

Getting Started

Quick Start

Install vorpal into your project:

$ npm install vorpal --save

Create a .js file and add the following:

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

vorpal
  .command('foo', 'Outputs "bar".')
  .action(function(args, callback) {
    this.log('bar');
    callback();
  });

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

This creates an instance of Vorpal, adds a command which logs "bar", sets the prompt delimiter to say "myapp$", and shows the prompt.

Run your project file. Your Node app has become a CLI:

$ node server.js
myapp~$

Try out your "foo" command.

myapp~$ foo
bar
myapp~$

Now type "help" to see Vorpal's built in commands in addition to "foo":

myapp~$ help

  Commands

    help [command]    Provides help for a given command.
    exit [options]    Exits instance of Vorpal.
    foo               Outputs "bar".

myapp~$

There's the basics. Once you get the hang of it, follow this tutorial or read on to learn what else Vorpal can do.

Community

Questions? Use the vorpal.js StackOverflow tag for fast answers that help others, or jump into chat on Gitter.

API

Command
Mode
Catch
CommandInstance
UI
Vorpal
Events

Extensions

You can build your own Vorpal commands and extensions.

FAQ

Why Vorpal?

One, two! One, two! and through and through
The vorpal blade went snicker-snack!
He left it dead, and with its head
He went galumphing back.

Lewis Carroll, Jabberwocky
Life Goals:
  • Build a popular framework based on the Jabberwocky poem.

License

MIT © David Caccavella

NPM DownloadsLast 30 Days