0.1.12 • Published 3 years ago

@lkmx/cli v0.1.12

Weekly downloads
-
License
ISC
Repository
-
Last release
3 years ago

LKMX CLI

This simple library is meant to streamline the process of building CLIs with nodejs.

Documentation

The main concept to build a CLI are the commands, these are the main actions available to the user.

The commands have the following structure:

FieldTypeDescription
nameStringThe name of the command.
descriptionStringA description for the command.
argumentObjectAn object containing a key and a description for the argument that follows the command.
optionsArrayAn array with the options supported by the command in the form of objects.
actionFunctionA function to be executed when the used invokes the specified command. The function receives the argument and an object with the options as parameters.

Commands

Create one file per command. For example, split.js:

module.exports = {
    name: 'split',
    description: 'Split a string as substrings and display them as an array',
    argument: {
        key: '<string>',
        description: 'string to split'
    },
    options: [
        {
            key: '--first',
            description: 'display just the first substring',
        },
        {
            key: '-s, --separator <char>',
            description: 'separator character',
            default: ','
        }
    ],
    requiredOptions: [
        {
            key: '-ro, --req-option <option>',
            description: 'option',
            default: 'default value to be suggested',
            choices: ['small', 'medium', 'large'],
        }
    ]
    action: (str, options) => {
        const limit = options.first ? 1 : undefined;
        console.log(str.split(options.separator, limit));
    }
}

CLI

Install dependencies

npm install @lkmx/cli@0.1.6

Code CLI

Use the following code as a template to develop your own CLI

// Import @lkmx/cli library
const CLI = require('@lkmx/cli')

// Import the custom commands 
const split = require('./commands/split.js');
const example = require('./commands/example.js');

// Initialize the CLI
const cli = new CLI(
    'string-util',
    'CLI to some Javascript string utilities',
    '0.1.0'
);

// Add all the commands
cli.add(split);
cli.add(example);

// Execute the CLI
cli.exec();

Development

In order to develop over this simple library a new CLI needs to be created and using npm link perform the necessary changes.

0.1.12

3 years ago

0.1.9

3 years ago

0.1.8

3 years ago

0.1.7

3 years ago

0.1.6

3 years ago

0.1.5

3 years ago

0.1.4

3 years ago

0.1.3

3 years ago

0.1.2

3 years ago

0.1.1

3 years ago

0.1.0

3 years ago