command-interface
Build powerful command-line interfaces from simple ES6 modules.
Last updated 10 months ago by philcockfield .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install command-interface 
SYNC missed versions from official npm registry.

Build Status Title

Build powerful command-line interfaces from simple ES6 modules.

Usage

Each command is defined within an ES module like so:

// commands/foo.cmd.js

export const name = 'foo';
export const description = 'A thing that does something.';
export const alias = 'f'; // String or Array.
export const group = 'Utilities';

export const args = {
  'param1': 'the first parameter',
  'param2': 'the second param',
  '--foo': 'a boolean flag',
};

export const validate = (args) => args;

export default (args) {
  // Run the command.
};

All exports are optional. If a name is omitted the name of the module is assumed. The only thing you really need is the default export function to invoke when the command is run.

If you don't wish to export the command as a default export, your can export a function named cmd, eg:

export async function cmd(args) {
  // Run the command.
}

To initialize the CLI, from the entry point of your module pass a glob pattern representing your JS modules that are commands. Typically these have a .cmd.js suffix:

import command from 'command-interface';
command('./**/*.cmd.js');

This will load all modules with the .cmd.js suffix anywhere within the project and produce the following index list when run with no command argument:

Index

Command Help

To get details on a specific command:

node . foo -h

Command Help

Run a Command

node . foo param1 flag=123 -f

The parameter and option arguments are passed to the command function as the args parameter.

{
  args: ['param1'],
  options: { flag: 123, f: true },
}

See minimist for more.

Example

cd lib/examples
node .

Tests

npm test

Usages

  • msync - A powerful toolkit for building and syncing multiple node-modules in a flexibly defined workspace.

  • new-file - Simple file templates.

Next

  • Update checker

Current Tags

  • 4.2.1                                ...           latest (10 months ago)

56 Versions

  • 4.2.1                                ...           10 months ago
  • 4.2.0                                ...           10 months ago
  • 4.1.0                                ...           2 years ago
  • 4.0.7                                ...           2 years ago
  • 4.0.6                                ...           2 years ago
  • 4.0.5                                ...           2 years ago
  • 4.0.4                                ...           2 years ago
  • 4.0.3                                ...           2 years ago
  • 4.0.2                                ...           2 years ago
  • 4.0.1                                ...           2 years ago
  • 4.0.0                                ...           2 years ago
  • 3.0.25                                ...           3 years ago
  • 3.0.24                                ...           3 years ago
  • 3.0.23                                ...           4 years ago
  • 3.0.22                                ...           4 years ago
  • 3.0.21                                ...           4 years ago
  • 3.0.20                                ...           4 years ago
  • 3.0.19                                ...           4 years ago
  • 3.0.18                                ...           4 years ago
  • 3.0.17                                ...           4 years ago
  • 3.0.16                                ...           4 years ago
  • 3.0.15                                ...           4 years ago
  • 3.0.14                                ...           4 years ago
  • 3.0.13                                ...           4 years ago
  • 3.0.12                                ...           4 years ago
  • 3.0.11                                ...           4 years ago
  • 3.0.10                                ...           4 years ago
  • 3.0.9                                ...           4 years ago
  • 3.0.8                                ...           4 years ago
  • 3.0.7                                ...           4 years ago
  • 3.0.6                                ...           4 years ago
  • 3.0.5                                ...           4 years ago
  • 3.0.4                                ...           4 years ago
  • 3.0.3                                ...           4 years ago
  • 3.0.2                                ...           4 years ago
  • 3.0.1                                ...           4 years ago
  • 3.0.0                                ...           4 years ago
  • 2.4.1                                ...           4 years ago
  • 2.4.0                                ...           4 years ago
  • 2.3.0                                ...           4 years ago
  • 2.2.1                                ...           4 years ago
  • 2.2.0                                ...           4 years ago
  • 2.1.4                                ...           4 years ago
  • 2.1.3                                ...           4 years ago
  • 2.1.2                                ...           4 years ago
  • 2.1.1                                ...           4 years ago
  • 2.1.0                                ...           4 years ago
  • 2.0.4                                ...           4 years ago
  • 2.0.3                                ...           4 years ago
  • 2.0.2                                ...           4 years ago
  • 2.0.1                                ...           4 years ago
  • 2.0.0                                ...           4 years ago
  • 1.0.3                                ...           4 years ago
  • 1.0.2                                ...           4 years ago
  • 1.0.1                                ...           4 years ago
  • 1.0.0                                ...           4 years ago
Downloads
Today 0
This Week 0
This Month 2
Last Day 0
Last Week 1
Last Month 0
Dependencies (11)
Dev Dependencies (4)

Copyright 2014 - 2016 © taobao.org |