diff --git a/argv.js b/argv.js index 38178be..85d8e96 100644 --- a/argv.js +++ b/argv.js @@ -424,17 +424,19 @@ object.Constructor('Parser', { // / // |<------+-------+------>| // - // -o, --option=VALUE - option doc + // -o, --option=VALUE - option doc // __ _ __ - // \ \ \ - // \ \ +---- .helpColumnPrefix ('- ') - // \ \ - // \ +--------------- .helpValueSeparator ('=') - // \ - // +---------------------- .helpArgumentSeparator (', ') + // _ \ \ \ + // \ \ \ +---- .helpColumnPrefix ('- ') + // \ \ \ + // \ \ +--------------- .helpValueSeparator ('=') + // \ \ + // \ +---------------------- .helpArgumentSeparator (', ') + // \ + // +----------------------- .helpShortOptionSize (2 chars) // - // doc config... helpColumnOffset: 3, + helpShortOptionSize: 2, helpColumnPrefix: '- ', helpArgumentSeparator: ', ', helpValueSeparator: '=', @@ -471,7 +473,8 @@ object.Constructor('Parser', { priority: 99, handler: function(argv, key, value){ var that = this - var sep = this.helpArgumentSeparator + var sep = this.helpArgumentSeparator || ', ' + var short = this.helpShortOptionSize || 1 var expandVars = this.expandTextVars.bind(this) var formDoc = function(doc, handler){ var info = [ @@ -529,14 +532,20 @@ object.Constructor('Parser', { .sort(function(a, b){ return a.length - b.length}) // form: "-x, --xx" - .map(function(o, i){ - return o.length <= 2 ? + .map(function(o, i, l){ + return o.length <= 1 + short ? o // no short options -> offset first long option... : i == 0 ? - ' '.repeat(sep.length + 2) +'-'+ o + ' '.repeat(1 + short + sep.length) +'-'+ o + // short option shorter than 1 + short + // -> offset first long option by difference... + : i == 1 ? + ' '.repeat(1 + short - l[0].length || 0) +'-'+ o // add extra '-' to long options... - : '-'+ o }) + : o.length > short ? + '-'+ o + : o }) .join(sep), ...(arg ? [arg] diff --git a/package.json b/package.json index b2938bd..70ba0c7 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ig-argv", - "version": "2.4.0", + "version": "2.4.1", "description": "simple argv parser", "main": "argv.js", "scripts": { diff --git a/test.js b/test.js index 3e322ce..01da39e 100644 --- a/test.js +++ b/test.js @@ -75,6 +75,9 @@ argv.Parser({ arg: 'STR | str', collect: 'string|\t', }, + //'-a': '-ab', + '-sh': { + doc: 'short option', }, '-test': argv.Parser({