Alter usage message style

Use sections and env hints per trentm's suggestion.
This commit is contained in:
Patrick Mooney 2014-06-19 19:19:36 -05:00
parent 3e43fb3d0c
commit 8cd59a5a5d
5 changed files with 128 additions and 124 deletions

View File

@ -24,6 +24,25 @@ dashdash.addOptionType({
var opts = [
{
names: ['file', 'f'],
type: 'string',
help: 'Input file',
helpArg: 'FILE'
},
{ group: 'General Options' },
{
names: ['help', 'h'],
type: 'bool',
help: 'Print this help and exit.'
},
{
names: ['debug', 'd'],
type: 'integer',
help: 'Set debug level <0-2>',
helpArg: 'LEVEL'
},
{ group: 'Connection Options' },
{
names: ['url', 'u'],
type: 'string',
@ -44,29 +63,12 @@ var opts = [
helpArg: 'PASSWD',
default: ''
},
{
names: ['file', 'f'],
type: 'string',
help: 'Input file',
helpArg: 'FILE'
},
{
names: ['insecure', 'i'],
type: 'bool',
env: 'LDAPJS_TLS_INSECURE',
help: 'Disable SSL certificate verification',
default: false
},
{
names: ['debug', 'd'],
type: 'integer',
help: 'Set debug level <0-2>',
helpArg: 'LEVEL'
},
{
names: ['help', 'h'],
type: 'bool',
help: 'Print this help and exit.'
}
];
var parser = dashdash.createParser({options: opts});
@ -76,11 +78,9 @@ var parser = dashdash.createParser({options: opts});
///--- Helpers
function usage(code, message) {
var _opts = parser.help();
var msg = (message ? message + '\n' : '') +
'usage: ' + path.basename(process.argv[1]) +
' <arguments> [JSON]\n' + _opts;
'Usage: ' + path.basename(process.argv[1]) + ' [OPTIONS] [JSON]\n\n' +
parser.help({includeEnv: true});
process.stderr.write(msg + '\n');
process.exit(code);
@ -133,7 +133,7 @@ if (!parsed.file) {
}
if (!parsed.file)
usage(1, 'either -f or stdin must be used for adding objects');
usage(1, 'either -f or arguments must be used for adding objects');
if (parsed.debug)
logLevel = (parsed.debug > 1 ? 'trace' : 'debug');

View File

@ -24,6 +24,31 @@ dashdash.addOptionType({
var opts = [
{
names: ['attribute', 'a'],
type: 'string',
help: 'Comparison attribute',
helpArg: 'ATTR'
},
{
names: ['value', 'v'],
type: 'string',
help: 'Comparison value',
helpArg: 'VAL'
},
{ group: 'General Options' },
{
names: ['help', 'h'],
type: 'bool',
help: 'Print this help and exit.'
},
{
names: ['debug', 'd'],
type: 'integer',
help: 'Set debug level <0-2>',
helpArg: 'LEVEL'
},
{ group: 'Connection Options' },
{
names: ['url', 'u'],
type: 'string',
@ -44,35 +69,12 @@ var opts = [
helpArg: 'PASSWD',
default: ''
},
{
names: ['attribute', 'a'],
type: 'string',
help: 'Comparison attribute',
helpArg: 'ATTR'
},
{
names: ['value', 'v'],
type: 'string',
help: 'Comparison value',
helpArg: 'VAL'
},
{
names: ['insecure', 'i'],
type: 'bool',
env: 'LDAPJS_TLS_INSECURE',
help: 'Disable SSL certificate verification',
default: false
},
{
names: ['debug', 'd'],
type: 'integer',
help: 'Set debug level <0-2>',
helpArg: 'LEVEL'
},
{
names: ['help', 'h'],
type: 'bool',
help: 'Print this help and exit.'
}
];
var parser = dashdash.createParser({options: opts});
@ -82,10 +84,9 @@ var parser = dashdash.createParser({options: opts});
///--- Helpers
function usage(code, message) {
var _opts = parser.help();
var msg = (message ? message + '\n' : '') +
'usage: ' + path.basename(process.argv[1]) + ' <arguments> <DN>\n' + _opts;
'Usage: ' + path.basename(process.argv[1]) + ' [OPTIONS] DN\n\n' +
parser.help({includeEnv: true});
process.stderr.write(msg + '\n');
process.exit(code);

View File

@ -24,6 +24,19 @@ dashdash.addOptionType({
var opts = [
{ group: 'General Options' },
{
names: ['help', 'h'],
type: 'bool',
help: 'Print this help and exit.'
},
{
names: ['debug', 'd'],
type: 'integer',
help: 'Set debug level <0-2>',
helpArg: 'LEVEL'
},
{ group: 'Connection Options' },
{
names: ['url', 'u'],
type: 'string',
@ -50,17 +63,6 @@ var opts = [
env: 'LDAPJS_TLS_INSECURE',
help: 'Disable SSL certificate verification',
default: false
},
{
names: ['debug', 'd'],
type: 'integer',
help: 'Set debug level <0-2>',
helpArg: 'LEVEL'
},
{
names: ['help', 'h'],
type: 'bool',
help: 'Print this help and exit.'
}
];
var parser = dashdash.createParser({options: opts});
@ -70,10 +72,9 @@ var parser = dashdash.createParser({options: opts});
///--- Helpers
function usage(code, message) {
var _opts = parser.help();
var msg = (message ? message + '\n' : '') +
'usage: ' + path.basename(process.argv[1]) + ' <arguments> <DN>\n' + _opts;
'Usage: ' + path.basename(process.argv[1]) + ' [OPTIONS] DN\n\n' +
parser.help({includeEnv: true});
process.stderr.write(msg + '\n');
process.exit(code);

View File

@ -24,6 +24,37 @@ dashdash.addOptionType({
var opts = [
{
names: ['attribute', 'a'],
type: 'string',
help: 'Attribute to modify',
helpArg: 'ATTR'
},
{
names: ['value', 'v'],
type: 'string',
help: 'Desired value',
helpArg: 'VAL'
},
{
names: ['type', 't'],
type: 'string',
help: 'Attribute type',
helpArg: 'TYPE'
},
{ group: 'General options' },
{
names: ['help', 'h'],
type: 'bool',
help: 'Print this help and exit.'
},
{
names: ['debug', 'd'],
type: 'integer',
help: 'Set debug level <0-2>',
helpArg: 'LEVEL'
},
{ group: 'Connection Options' },
{
names: ['url', 'u'],
type: 'string',
@ -44,41 +75,12 @@ var opts = [
helpArg: 'PASSWD',
default: ''
},
{
names: ['attribute', 'a'],
type: 'string',
help: 'Attribute to modify',
helpArg: 'ATTR'
},
{
names: ['value', 'v'],
type: 'string',
help: 'Desired value',
helpArg: 'VAL'
},
{
names: ['type', 't'],
type: 'string',
help: 'Attribute type',
helpArg: 'TYPE'
},
{
names: ['insecure', 'i'],
type: 'bool',
env: 'LDAPJS_TLS_INSECURE',
help: 'Disable SSL certificate verification',
default: false
},
{
names: ['debug', 'd'],
type: 'integer',
help: 'Set debug level <0-2>',
helpArg: 'LEVEL'
},
{
names: ['help', 'h'],
type: 'bool',
help: 'Print this help and exit.'
}
];
var parser = dashdash.createParser({options: opts});
@ -88,10 +90,9 @@ var parser = dashdash.createParser({options: opts});
///--- Helpers
function usage(code, message) {
var _opts = parser.help();
var msg = (message ? message + '\n' : '') +
'usage: ' + path.basename(process.argv[1]) + ' <arguments> <DN>\n' + _opts;
'Usage: ' + path.basename(process.argv[1]) + ' [OPTIONS] DN\n\n' +
parser.help({includeEnv: true});
process.stderr.write(msg + '\n');
process.exit(code);

View File

@ -43,26 +43,6 @@ dashdash.addOptionType({
var opts = [
{
names: ['url', 'u'],
type: 'string',
help: 'LDAP server URL',
helpArg: 'URL',
default: 'ldap://127.0.0.1:389'
},
{
names: ['binddn', 'D'],
type: 'ldap.DN',
help: 'Bind DN',
default: ''
},
{
names: ['password', 'w'],
type: 'string',
help: 'Bind password',
helpArg: 'PASSWD',
default: ''
},
{
names: ['base', 'b'],
type: 'ldap.DN',
@ -101,12 +81,11 @@ var opts = [
helpArg: 'OID',
default: []
},
{ group: 'General Options' },
{
names: ['insecure', 'i'],
names: ['help', 'h'],
type: 'bool',
env: 'LDAPJS_TLS_INSECURE',
help: 'Disable SSL certificate verification',
default: false
help: 'Print this help and exit.'
},
{
names: ['debug', 'd'],
@ -114,10 +93,33 @@ var opts = [
help: 'Set debug level <0-2>',
helpArg: 'LEVEL'
},
{ group: 'Connection Options' },
{
names: ['help', 'h'],
names: ['url', 'u'],
type: 'string',
help: 'LDAP server URL',
helpArg: 'URL',
default: 'ldap://127.0.0.1:389'
},
{
names: ['binddn', 'D'],
type: 'ldap.DN',
help: 'Bind DN',
default: ''
},
{
names: ['password', 'w'],
type: 'string',
help: 'Bind password',
helpArg: 'PASSWD',
default: ''
},
{
names: ['insecure', 'i'],
type: 'bool',
help: 'Print this help and exit.'
env: 'LDAPJS_TLS_INSECURE',
help: 'Disable SSL certificate verification',
default: false
}
];
var parser = dashdash.createParser({options: opts});
@ -127,11 +129,10 @@ var parser = dashdash.createParser({options: opts});
///--- Helpers
function usage(code, message) {
var _opts = parser.help();
var msg = (message ? message + '\n' : '') +
'usage: ' + path.basename(process.argv[1]) +
' <arguments> <filter> [attributes]\n' + _opts;
'Usage: ' + path.basename(process.argv[1]) +
' [OPTIONS] FILTER [ATTRIBUTES...]\n\n' +
parser.help({includeEnv: true});
process.stderr.write(msg + '\n');
process.exit(code);