Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const _ = require( 'lodash' );
- const optionDefine = {
- help: {
- type: 'boolean',
- alias: 'h',
- default: false,
- description: 'display this help'
- },
- list: {
- type: 'boolean',
- alias: 'l',
- default: false,
- description: 'display tasks'
- },
- silent: {
- type: 'boolean',
- default: false,
- description: 'log errors only'
- },
- debug: {
- type: 'boolean',
- default: false,
- description: ''
- },
- version: {
- type: 'boolean',
- alias: 'v',
- default: false,
- description: 'display version'
- }
- };
- optionDefine[Symbol.iterator] = function* () {
- for ( let key in this ) {
- yield [ key, this[key] ];
- }
- };
- function showHelp(aOptionDefine) {
- const maxLength = _
- .chain( _.keys( optionDefine ) )
- .map( name => name.length )
- .max()
- .value();
- console.log( 'Options:' );
- for ( let [name, opts] of aOptionDefine ) {
- process.stdout.write( ' ' );
- if ( opts.alias === undefined ) {
- process.stdout.write( ' ' );
- } else {
- process.stdout.write( `-${opts.alias},` );
- }
- process.stdout.write( ` --${name}` );
- process.stdout.write( _.repeat( ' ', ( maxLength - name.length ) + 2 ) );
- process.stdout.write( opts.description );
- process.stdout.write( '\n' );
- }
- }
- showHelp( optionDefine );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement