}) .demandCommand() .help() .parse();
// eslint-disable-next-line const run = () => yargs .version(cliVersion) .commandDir(COMMAND_DIR) .demandCommand() .help() .argv
describe('init command', () => { it('returns help output', async () => { // Initialize parser using the command module const parser = yargs.command(require('./init')).help(); // Run the command module with --help as argument const output = await new Promise(resolve => { parser.parse('--help', (err, argv, output) => { resolve(output); }); }); // Verify the output is correct expect(output).toEqual( expect.stringContaining('Setup wizard for creating config file') ); }); });
parseCommandLine() { let options = this._yargs(process.argv).default('windowsize','800x600').wrap(100); options.usage('Electron command line'); options.alias('ws', 'windowsize').string('ws').describe('ws','set window size (Ex: 800x600)'); options.alias('d', 'debug').boolean('1').describe('1', 'Autostart dev tools'); options.alias('u', 'userdata').string('u').describe('u', 'set userdata directory'); options.alias('v', 'version').boolean('v').describe('v', 'Print the version.'); options.alias('h', 'help').boolean('h').describe('h', 'Print this usage message.'); this._args = options.argv; if (this._args.help) { process.stdout.write(options.help()); process.exit(0); } if (this._args.version) { process.stdout.write(`Electron Version : ${process.versions.electron}\n`); process.stdout.write('GLBrowser Version : 0.0.1\n'); process.exit(0); } }
cli .command( 'init [<template-name>]', 'Scaffold a Basys project using a starter template', yargs => { yargs.positional('template-name', { type: 'string', describe: 'username/repo from GitHub or local directory', }); }, ) .command('help [<command>]', 'Show help for basys-cli', yargs => { yargs.positional('command', {type: 'string'}); }) .help()
require('yargs') .usage('npm run configure -- <arguments>') .describe('p', 'The panel url to pull the configuration from') .alias('p', 'panel-url') .describe('t', 'The configuration token') .alias('t', 'token') .boolean('o') .describe('o', 'Overwrite existing configuration file') .alias('o', 'overwrite') .alias('h', 'help') .check(checkParams) .help('h') .fail((msg, err, yargs) => { console.error(err.message); console.log(yargs.help()); process.exit(1); })
function init (data) { if (data && semver.gt(data.version, version)) { console.log(chalk.red(`------ You're running gloria in version ${version}, the latest version is ${data.version}. Run 'npm install -g gloria' to get the latest version ------`)); } // Using yargs to identify commands and arguments // https://www.npmjs.com/package/yargs require(`yargs`) .commandDir(`../commands`) .alias('v', 'version') .version(require(`../version`)) .help() .usage(`Gloria is a static site generator. Use the command init to get started.`) .epilogue(`For more information, check out the documentation in github.com/gloriajs/gloria`) .argv; }
yargs .option('types', { type: 'array', default: [] }) .option('limit', { default: 1000 }) .option('dry-run', { default: true }) .check(argv => { if (argv.types.length === 0) { return 'Check --types. Should contain at least one type.' } return true }) .help() .version()
/* https://medium.com/stackfame/how-to-run-shell-script-file-or-command-using-nodejs-b9f2455cb6b7 https://dzone.com/articles/execute-unix-command-nodejs http://yargs.js.org/docs/#api-aliaskey-alias */ argv.command('add', 'Adds the arguments', () => {}, (args) => { console.log(args); }) .option('size', { alias: 's', describe: 'choose a size', choices: ['xs', 's', 'm', 'l', 'xl'] }) .alias('i', 'ingredient') .help()
require('yargs') .command('* <file-path>', 'parse and convert the input file', (yargs) => { yargs.positional('file-path', { describe: 'the input USFM or JSON file to be parsed and converted', }); }) .alias('l', 'level') .describe('l', 'specify the level of strictness in parsing') .choices('l', ['relaxed']) .describe('filter', 'filters out only the specific contents from input USFM') .choices('filter', ['scripture']) .describe('format', 'specifies the output file format') .choices('format', ['csv', 'tsv', 'usfm', 'json']) .alias('o', 'output') .describe('o', 'specify the fully qualified file path for output.') .alias('h', 'help') .alias('v', 'version') .help('help')
yargs .option('indices', { alias: ['i', 'index'], array: true, choices: mappings.list.map(({ name }) => name) }) .option('switch', { alias: 's', boolean: true, default: true }) .option('inserts', { boolean: true, default: true }) .option('flush', { boolean: true, default: false }) .help() .version()
}) .demandCommand() .help() .parse();
cli .command( 'init [<template-name>]', 'Scaffold a Basys project using a starter template', yargs => { yargs.positional('template-name', { type: 'string', describe: 'username/repo from GitHub or local directory', }); }, ) .command('help [<command>]', 'Show help for basys-cli', yargs => { yargs.positional('command', {type: 'string'}); }) .help()
yargs .option('types', { type: 'array', default: [] }) .option('limit', { default: 1000 }) .option('dry-run', { default: true }) .check(argv => { if (argv.types.length === 0) { return 'Check --types. Should contain at least one type.' } return true }) .help() .version()