cmdl

A simple, yet powerful command-line interface builder

npm install cmdl
9 downloads in the last week
18 downloads in the last month

Build Status

cmdl 0.2.1

A simple, yet powerful command-line interface builder.

Installation

NPM

API Reference

cmdl.init( options )

Initializes your CLI.

cli.init({
    version: '0.0.1',
    name: 'DemoCLI',
    promptEnabled: true
});

Options:

  • version: the version of your CLI. this option is mandatory
  • name: the name of your CLI. Mandatory if you use the prompt feature
  • promptEnabled: set this to true if you want to enable the prompt feature (default: false)

cmdl.addCommand( properties )

Adds a CLI command. A command can have several options.

cli.addCommand({
    name: 'create',
    description: 'create a new blog',
    options: [{
        name: 'name',
        short: 'n',
        type: 'string',
        description: 'blog name',
        example: 'cmdl-test create -n testblog'
    }],
    callback: function(args) {
        console.log("create method was called: ", args);
    }
});

cmdl.addOption( properties )

Adds a CLI option. The option can take one value as parameter.

cli.addOption({
    name: 'port',
    short: 'p',
    type: 'int',
    description: 'port',
    example: 'cmdl-test -p 8080',
    callback: function(port) {
        console.log("Port is: ", port);
    }
});

cmdl.prompt( schema, callback )

Creates an interactive prompt for your CLI.

var schema = [
    {
        description: 'Enter your username',
        name: 'username',
        resultequired: true
    },
    {
        description: 'Enter your password',
        name: 'password',
        hidden: true,
        conform: function (value) {
            return true;
        }
    }
];

cli.prompt(schema, function (err, result) {
    console.log('cmdl received:');
    console.log('  username: ' + result.username);
    console.log('  password: ' + result.password);
});

As of version 0.2.0, cdml makes use of flatiron's prompt module for its prompt feature. Please take a look at their README for the various options (cdml.prompt is a wrapper around prompt.get).

cmdl.execute( command, callback )

Executes a system command (for UNIX-based systems only).

cli.execute('ls -alF', function(err, stdout, stderr) {
    if(err) throw err;
    if(stderr) throw stderr;
    console.log("responsse: ", stdout);
});

cmdl.listen()

Enables the CLI.

cli.listen();

Test

npm test

Demo

npm install -g cmdl
cmdl-test -h

LICENSE

The MIT License (MIT)

Copyright (c) 2013 Stéphane P. Péricat

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

npm loves you