0.2.0 • Published 1 year ago

bitandblack-console v0.2.0

Weekly downloads
-
License
MIT
Repository
-
Last release
1 year ago

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.

0.1.0

1 year ago

0.1.2

1 year ago

0.2.0

1 year ago

0.1.1

1 year ago

0.0.1

2 years ago

0.0.0

2 years ago