Giter VIP home page Giter VIP logo

clapp's Introduction

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.