UNPKG

subcli

Version:

helpers for creating command-line interfaces that support subcommands

62 lines (56 loc) 1.77 kB
'use strict'; var _lib = require('../lib'); function example(argv) { var commandDescriptor = { name: 'act', description: 'act happy or sad', usage: 'act [options] [ <happy|sad> [options for happy or sad] ]', commands: [{ name: 'happy', description: 'act happy, like you just cannot imagine anything at all in the world that could be better than right now', usage: 'happy [options]', options: [{ name: 'gleeful', abbr: 'g', boolean: true, help: 'act really, REALLY happy' }] }, { name: 'sad', description: 'act sad', usage: 'sad [options]', options: [{ name: 'miserable', abbr: 'm', boolean: true, help: 'act really, REALLY sad' }] }], options: [{ name: 'be', abbr: 'b', boolean: true, help: "don't _act_, actually _be_; this means that it won't be pretending, it will be 100% completely and positively real" }], examples: [{ example: 'act happy', description: 'pretend to be in a good mood' }, { example: 'act -b sad --miserable', description: 'be in an incredibly bad bood, like simply the absolutely positively worst blasted day you have ever had ... like ever, really' }] }; var args = (0, _lib.parse)(commandDescriptor, argv); var usageMessage = (0, _lib.usage)(commandDescriptor, args, { commandPrefix: '/', maxWidth: 76 }); if (!usageMessage) { console.info('No usage printed since neither -h or --help was passed.'); console.log('\nParsed args:', args); } else { console.info(usageMessage); console.log('\nParsed args:', args); } } if (!module.parent) { var argv = process.argv.slice(2); example(argv); }