Comparing version 0.3.1 to 0.3.2
53
cli.js
@@ -30,3 +30,3 @@ /** | ||
short_tags = [], opt_list, parsed = {}, | ||
usage, argv_parsed, command_list, | ||
usage, argv_parsed, command_list, commands, | ||
daemon, daemon_arg, no_color, show_debug; | ||
@@ -258,7 +258,11 @@ | ||
*/ | ||
cli.parse = function (opts, commands) { | ||
cli.parse = function (opts, command_def) { | ||
var default_val, i, parsed = cli.options, seen, | ||
catch_all = !opts; | ||
opt_list = opts || {}; | ||
commands = command_def; | ||
command_list = commands || []; | ||
if (typeof commands === 'object') { | ||
command_list = Object.keys(commands); | ||
} | ||
while (o = cli.next()) { | ||
@@ -339,3 +343,3 @@ seen = false; | ||
} | ||
console.log(cli.app + ' v' + cli.version); | ||
console.error(cli.app + ' v' + cli.version); | ||
process.exit(); | ||
@@ -376,3 +380,8 @@ } else if (enable.daemon && (o === 'd' || o === 'daemon')) { | ||
if (cli.args.length === 0) { | ||
cli.fatal('A command is required' + (enable.help ? '. Please see --help for more information' : '')); | ||
if (enable.help) { | ||
cli.getUsage(); | ||
} else { | ||
cli.fatal('A command is required (' + command_list.join(', ') + ').'); | ||
} | ||
process.exit(1); | ||
} else { | ||
@@ -584,4 +593,4 @@ cli.command = cli.autocompleteCommand(cli.args.shift()); | ||
usage = usage || cli.app + ' [OPTIONS]' + (command_list ? ' <command>' : '') + ' [ARGS]'; | ||
console.log('\x1b[1mUsage\x1b[0m:\n ' + usage); | ||
console.log('\n\x1b[1mOptions\x1b[0m: '); | ||
console.error('\x1b[1mUsage\x1b[0m:\n ' + usage); | ||
console.error('\n\x1b[1mOptions\x1b[0m: '); | ||
for (opt in opt_list) { | ||
@@ -631,3 +640,3 @@ | ||
line += optional ? ' (Default is ' + optional + ')' : ''; | ||
console.log(line); | ||
console.error(line); | ||
@@ -638,34 +647,36 @@ seen_opts.push(short); | ||
if (enable.timeout && seen_opts.indexOf('t') === -1 && seen_opts.indexOf('timeout') === -1) { | ||
console.log(pad(' -t, --timeout N', switch_pad) + 'Exit if the process takes longer than N seconds'); | ||
console.error(pad(' -t, --timeout N', switch_pad) + 'Exit if the process takes longer than N seconds'); | ||
} | ||
if (enable.status) { | ||
if (seen_opts.indexOf('k') === -1 && seen_opts.indexOf('no-color') === -1) { | ||
console.log(pad(' -k, --no-color', switch_pad) + 'Omit color from output'); | ||
console.error(pad(' -k, --no-color', switch_pad) + 'Omit color from output'); | ||
} | ||
if (seen_opts.indexOf('debug') === -1) { | ||
console.log(pad(' --debug', switch_pad) + 'Show debug information'); | ||
console.error(pad(' --debug', switch_pad) + 'Show debug information'); | ||
} | ||
} | ||
if (enable.catchall && seen_opts.indexOf('c') === -1 && seen_opts.indexOf('catch') === -1) { | ||
console.log(pad(' -c, --catch', switch_pad) + 'Catch unanticipated errors'); | ||
console.error(pad(' -c, --catch', switch_pad) + 'Catch unanticipated errors'); | ||
} | ||
if (enable.daemon && seen_opts.indexOf('d') === -1 && seen_opts.indexOf('daemon') === -1) { | ||
console.log(pad(' -d, --daemon [ARG]', switch_pad) + 'Daemonize the process. Control the daemon using [start, stop, restart, log, pid]'); | ||
console.error(pad(' -d, --daemon [ARG]', switch_pad) + 'Daemonize the process. Control the daemon using [start, stop, restart, log, pid]'); | ||
} | ||
if (enable.version && seen_opts.indexOf('v') === -1 && seen_opts.indexOf('version') === -1) { | ||
console.log(pad(' -v, --version', switch_pad) + 'Display the current version'); | ||
console.error(pad(' -v, --version', switch_pad) + 'Display the current version'); | ||
} | ||
if (enable.help && seen_opts.indexOf('h') === -1 && seen_opts.indexOf('help') === -1) { | ||
console.log(pad(' -h, --help', switch_pad) + 'Display help and usage details'); | ||
console.error(pad(' -h, --help', switch_pad) + 'Display help and usage details'); | ||
} | ||
if (command_list.length) { | ||
console.log('\n\x1b[1mCommands\x1b[0m: '); | ||
var list; | ||
if (command_list instanceof Array) { | ||
list = command_list; | ||
console.error('\n\x1b[1mCommands\x1b[0m: '); | ||
if (typeof commands === 'object') { | ||
for (var c in commands) { | ||
line = ' ' + pad(c, switch_pad - 2); | ||
line += trunc_desc(line, commands[c]); | ||
console.error(line); | ||
} | ||
} else { | ||
list = Object.keys(command_list); | ||
command_list.sort(); | ||
console.error(' ' + trunc_desc(' ', command_list.join(', '))); | ||
} | ||
command_list.sort(); | ||
console.log(' ' + trunc_desc(' ', command_list.join(', '))); | ||
} | ||
@@ -672,0 +683,0 @@ process.exit(); |
@@ -16,2 +16,2 @@ #!/usr/bin/env node | ||
console.log('Command is: ' + cli.command); | ||
console.log('Command is: ' + cli.command); |
{ "name" : "cli", | ||
"description" : "A tool for rapidly building command line apps", | ||
"version" : "0.3.1", | ||
"version" : "0.3.2", | ||
"homepage" : "http://github.com/chriso/cli", | ||
@@ -5,0 +5,0 @@ "keywords" : ["cli","command line","opts","parseopt","opt","args","console","argsparse","optparse","daemon","autocomplete","command","autocompletion"], |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
49203
1188