bitandblack-console
TypeScript icon, indicating that this package has built-in type declarations

0.2.0 • Public • Published

License npm version

Bit&Black Console

Create command line interfaces without pain.

This library is heavily inspired by the awesome Symfony Console.

Installation

This library is made for the use with Node. Add it to your project by running $ npm install bitandblack-console or $ yarn add bitandblack-console.

Usage

The Console tool consists of two parts: the commands and the application that executes them. To create a command, you need to create a class that extends the existing AbstractConsoleCommand class.

This is a simple command that outputs some text to the command line:

import { AbstractConsoleCommand, ConsoleCommandInterface, InputInterface, OutputInterface } from "bitandblack-console";

class TestCommand extends AbstractConsoleCommand {
    configure(): void {
        this
            .setName("test")
            .setDescription("This is my first command.")
        ;
    }

    execute(input: InputInterface, output: OutputInterface): number {
        output.writeln("It works!");
        return ConsoleCommandInterface.SUCCESS;
    }
}

export { TestCommand }

To make this command available in the console application, we need to initialize a Application object and add the TestCommand there.

Create a bin/console file with the following content:

#!/usr/bin/env node

const { Application } = require("bitandblack-console/src/Application");
const { TestCommand } = require("../src/Commands/TestCommand");

const application = new Application();
application
    .addCommand(new TestCommand())
    .run()
;

Now you are able to run your console application by calling $ bin/console and the test command by calling $ bin/console test.

Help

If you have any questions, feel free to contact us under hello@bitandblack.com.

Further information about Bit&Black can be found under www.bitandblack.com.

/bitandblack-console/

    Package Sidebar

    Install

    npm i bitandblack-console

    Weekly Downloads

    0

    Version

    0.2.0

    License

    MIT

    Unpacked Size

    72.4 kB

    Total Files

    57

    Last publish

    Collaborators

    • tobiaskoengeter