Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including clapp with all npm packages installed. Try it out:

var clapp = require("clapp")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

clapp v1.3.3

A tool for building command line apps that don't aren't necessarily built for the command line.

clapp NPM version Build Status Dependency Status Coverage percentage

A tool for building command line apps that aren't necessarily built for the command line.

Average time to resolve an issue Percentage of issues still open PRs Welcome

Installation

$ npm install --save clapp

Features

  • Input isn't restricted to node's process.argv, unlike other libraries, so you may use Clapp for a node cli app, or use it for anything alse. For instance, you may use it for a discord bot, where an user message is the input, and the bot behaves like a command line app.
  • Clapp also handles command execution. When using other command parsing libraries, you'd need to manually execute the command function by evaluating the user input. Clapp will execute the command for you if the user input satisfies your needs, or let the user know the error otherwise.
  • Clapp allows you to have precise control of user input: it takes care of required arguments, default values, data types, and data validation for you.
  • It also handles documentation. Clapp takes an "if you don't document it, go fuck yourself" apporach, meaning that it will simply not work if you don't document your app. For example, if you don't declare an argument that you expect the user to pass, Clapp will ignore it and not pass it back to you. But because of that, Clapp is able to easily print documentation to the user when they pass the --help flag.
  • Clapp handles the --version flag as well.

Usage

const Clapp = require('clapp');

let app = new Clapp.App({
    name: "Test App",
    desc: "An app that does the thing",
    prefix: "-testapp",
    version: "1.0",
    onReply: function(msg, context) {
        // Clapp will use this function to
        // communicate with the end user
        console.log(msg);
    }
});

app.addCommand(new Clapp.Command({
    name: "foo",
    desc: "An example command",
    fn: function(argv, context) {
        return "Foo was executed!"
    }
}));

let userInput = "-testapp foo";

// Checks if the user input is an acceptable command
if (app.isCliSentence(userInput)) {
    app.parseInput(userInput); // logs "Foo was executed!"
}

Please check out the docs for the full instructions!

License

Apache-2.0 © Pablo Rodríguez

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free