ls-age/expose

The easy way to expose a module for CLI usage

Stars 0
Current release v0.2.0-beta.1
View on GitHub

@ls-age/expose

Work in progress

The easy way to expose a module for CLI usage

CircleCI Greenkeeper badge

Installation

npm install --save @ls-age/expose

Usage

import Expose, { Command, NumberOption } from '@ls-age/expose';
import { version, description } from '../package.json';

const cli = new Expose({ description });
cli.addHelp();
cli.addVersion(version);

const testCommand = new Command({
  name: 'test',
  description: 'Just for testing',
  alias: 'try',
  run({ options }) {
    console.log('Running test command with options', options);
  },
});
testCommand.addOption(new NumberOption({
  name: 'log-level',
  description: 'Set log level',
  alias: 'l',
  async set(level) {
    console.log('Setting log level to', level);

    // Setting the log level takes some time, so we use an async function
    await new Promise(resolve => setTimeout(resolve, 1000));

    console.log('Log level was set');
  },
}));
cli.addCommand(testCommand);

cli.run();