From 8cd59a5a5d4785b894ec4a04e17a3d67b2352350 Mon Sep 17 00:00:00 2001 From: Patrick Mooney Date: Thu, 19 Jun 2014 19:19:36 -0500 Subject: [PATCH] Alter usage message style Use sections and env hints per trentm's suggestion. --- bin/ldapjs-add | 44 +++++++++++++++---------------- bin/ldapjs-compare | 53 ++++++++++++++++++------------------- bin/ldapjs-delete | 29 +++++++++++---------- bin/ldapjs-modify | 65 +++++++++++++++++++++++----------------------- bin/ldapjs-search | 61 ++++++++++++++++++++++--------------------- 5 files changed, 128 insertions(+), 124 deletions(-) diff --git a/bin/ldapjs-add b/bin/ldapjs-add index 14ce5b2..86c0a1d 100755 --- a/bin/ldapjs-add +++ b/bin/ldapjs-add @@ -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]) + - ' [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'); diff --git a/bin/ldapjs-compare b/bin/ldapjs-compare index 3eaeb69..d23faf4 100755 --- a/bin/ldapjs-compare +++ b/bin/ldapjs-compare @@ -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]) + ' \n' + _opts; + 'Usage: ' + path.basename(process.argv[1]) + ' [OPTIONS] DN\n\n' + + parser.help({includeEnv: true}); process.stderr.write(msg + '\n'); process.exit(code); diff --git a/bin/ldapjs-delete b/bin/ldapjs-delete index 1f5d069..a7fc7f2 100755 --- a/bin/ldapjs-delete +++ b/bin/ldapjs-delete @@ -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]) + ' \n' + _opts; + 'Usage: ' + path.basename(process.argv[1]) + ' [OPTIONS] DN\n\n' + + parser.help({includeEnv: true}); process.stderr.write(msg + '\n'); process.exit(code); diff --git a/bin/ldapjs-modify b/bin/ldapjs-modify index 85ce9e2..0982ef9 100755 --- a/bin/ldapjs-modify +++ b/bin/ldapjs-modify @@ -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]) + ' \n' + _opts; + 'Usage: ' + path.basename(process.argv[1]) + ' [OPTIONS] DN\n\n' + + parser.help({includeEnv: true}); process.stderr.write(msg + '\n'); process.exit(code); diff --git a/bin/ldapjs-search b/bin/ldapjs-search index 07a5516..6ec13f8 100755 --- a/bin/ldapjs-search +++ b/bin/ldapjs-search @@ -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]) + - ' [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);