Nice Paintings, Mondrian
    Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »

    konzolepublic

    Konzole

    Console applications in NodeJS made easy as hell.

    Konzole

    Usage

    Require a konzole within a simple node script and run it:

    var konzole = require('./konzole')('MY FIRST CONSOLE', "1.0.0");
     
    konzole.run();

    you will see an help script describing the commands that are registered within this console (only help, for now).

    Let's declare a new ls command that will simply console.log the contents of a directory:

    var konzole = require('konzole')('MY FIRST CONSOLE', "1.0.0");
    var kommand = require('kommand');
    var fs = require('fs');
     
    var ls = new kommand('Lists contents of a directory');
     
    ls.run = function(konzole) {
        console.log(fs.readdirSync('.'))
    };
     
    konzole.addCommand('ls', ls);
     
    konzole.run();

    et-voila:

    ls command

    Options

    To add options to your command, simply declare them as dependencies of your command:

    var kommand = require('kommand');
    var kommand = require('option');
     
    var ls = new kommand('Lists contents of a directory', [new option('d', 'dir', '.')]);
     
    ls.run = function(konzole, input) {
        console.log(fs.readdirSync(input.getOption('d')))
    };

    the three arguments of an option are:

    • its name (-d)
    • its alias (--dir)
    • its default value (.)

    Now you can simply use your pimped command with node index.js ls --dir=/home/you/something.

    Example console

    In this example we are adding to the console the already-seen ls command and a new, quote, command that will retrieve a random quote from the internet.

    Just like that.

    var konzole = require('konzole')('MY FIRST CONSOLE', "1.0.0");
    var kommand = require('kommand');
    var option  = require('option');
    var fs = require('fs');
    var colors = require('colors');
    var _ = require('lodash');
    var HTTP = require("q-io/http");
     
    var ls = new kommand('Lists contents of a directory', [new option('d', 'dir', '.')]);
    ls.run = function(konzole, input) {
        var directory = input.getOption('dir');
     
        console.log(fs.readdirSync(directory));
    };
     
    var quote = new kommand('Retrieves a random quote');
    quote.run = function(konzole, input) {
        HTTP.request({url: "http://www.iheartquotes.com/api/v1/random.json", method: 'GET'}).then(function(response){
            response.body.read().then(function (buffer) {
                console.log(JSON.parse(buffer.toString('UTF-8')).quote.inverse);
            });
        })
    };
     
    konzole.addCommand('ls', ls);
    konzole.addCommand('quote', quote);
     
    konzole.run();

    Konzole

    Have fun!

    Tests

    tests

    Gimme some time :)

    install

    npm i konzole

    Downloadsweekly downloads

    4

    version

    1.0.2

    license

    MIT

    homepage

    github.com

    last publish

    collaborators

    • avatar