Skip to content
/ expose Public

The easy way to expose a module for CLI usage

Notifications You must be signed in to change notification settings

ls-age/expose

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

@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();