@ainc/cli

The complete solution for node.js command-line interfaces,

Usage no npm install needed!

<script type="module">
  import aincCli from 'https://cdn.skypack.dev/@ainc/cli';
</script>

README

@ainc/cli

The complete solution for node.js command-line interfaces,

Install

$ yarn add @ainc/cli

Usage

Create commands program, as cli.js:

import { commander } from '@ainc/cli';

// create server program with 'init' and 'start' command
commander({
    name: 'server',
    usage: '[command] [options]',
    version: '0.0.1',
    description: 'web server',
    commands: {
        init: {
            description: 'init server',
        },
        start: {
            usage: '[options]',
            description: 'start server',
            isDefault: true,
        },
    },
});

Create command, as start.js:

import { command } from '@ainc/cli';

// create start server command
command({
    config: 'server.config',
    options: {
        root: {
            type: 'dir',
            alias: 'r',
            description: 'the base directory of server',
        },
        port: {
            type: 'number',
            alias: 'p',
            description: 'the port of server',
        },
        open: {
            type: 'boolean',
            description: 'open the default browser',
        },
    }
});