Giter VIP home page Giter VIP logo

command-interface's Introduction

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

command-interface's People

Contributors

frederickfogerty avatar philcockfield avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.