Skip to content

Latest commit

 

History

History
66 lines (52 loc) · 1.94 KB

File metadata and controls

66 lines (52 loc) · 1.94 KB

nodejsscriptDocs


nodejsscript / $ / api

Function: api()

api(usage, is_single?): Sade

A wrapper around the lukeed/sade: Smooth (CLI) Operator 🎶 package. In addition to the origin, $.api() supports to fill script name from script file name. Also, you can call *.parse() and it automatically use process.argv or use *.parse(options: {}) with custom argv key. This should be good balance between commander - npm and parsing arguments and writing help texts by hand. For more complex scripts just create full npm package.

$.api("", true)
.version("0.1.0")
.describe("NodeJS Script $ test")
.action(echo)
.parse();
$.api("copy <file> <destination>", true)
.version("0.1.0")
.describe("copy file simpulation")
.option("--force", "Overwrite file in destination.")
.action(function(file, destination, { force }){
	// copy file logic
})
.parse();
const prog= $.api('my-cli');
prog
  .version('1.0.5')
  .option('--global, -g', 'An example global flag')
  .option('-c, --config', 'Provide path to custom config', 'foo.config.js');
prog
  .command('build <src> <dest>')
  .describe('Build the source directory. Expects an `index.js` entry file.')
  .option('-o, --output', 'Change the name of the output file', 'bundle.js')
  .example('build src build --global --config my-conf.js')
  .example('build app public -o main.js')
  .action((src, dest, opts) => {
    echo(`> building from ${src} to ${dest}`);
    echo('> these are extra opts', opts);
  });
prog.parse();

Parameters

usage: string

The script name and usage ([optional]/<required>). If no name, then the script file name will be used.

is_single?: boolean

See __sade

Returns

Sade