aesthetic tweaking...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2020-07-27 19:33:57 +03:00
parent d3762f4f9c
commit f116282044
3 changed files with 26 additions and 14 deletions

35
argv.js
View File

@ -424,17 +424,19 @@ object.Constructor('Parser', {
// / // /
// |<------+-------+------>| // |<------+-------+------>|
// //
// -o, --option=VALUE - option doc // -o, --option=VALUE - option doc
// __ _ __ // __ _ __
// \ \ \ // _ \ \ \
// \ \ +---- .helpColumnPrefix ('- ') // \ \ \ +---- .helpColumnPrefix ('- ')
// \ \ // \ \ \
// \ +--------------- .helpValueSeparator ('=') // \ \ +--------------- .helpValueSeparator ('=')
// \ // \ \
// +---------------------- .helpArgumentSeparator (', ') // \ +---------------------- .helpArgumentSeparator (', ')
// \
// +----------------------- .helpShortOptionSize (2 chars)
// //
// doc config...
helpColumnOffset: 3, helpColumnOffset: 3,
helpShortOptionSize: 2,
helpColumnPrefix: '- ', helpColumnPrefix: '- ',
helpArgumentSeparator: ', ', helpArgumentSeparator: ', ',
helpValueSeparator: '=', helpValueSeparator: '=',
@ -471,7 +473,8 @@ object.Constructor('Parser', {
priority: 99, priority: 99,
handler: function(argv, key, value){ handler: function(argv, key, value){
var that = this var that = this
var sep = this.helpArgumentSeparator var sep = this.helpArgumentSeparator || ', '
var short = this.helpShortOptionSize || 1
var expandVars = this.expandTextVars.bind(this) var expandVars = this.expandTextVars.bind(this)
var formDoc = function(doc, handler){ var formDoc = function(doc, handler){
var info = [ var info = [
@ -529,14 +532,20 @@ object.Constructor('Parser', {
.sort(function(a, b){ .sort(function(a, b){
return a.length - b.length}) return a.length - b.length})
// form: "-x, --xx" // form: "-x, --xx"
.map(function(o, i){ .map(function(o, i, l){
return o.length <= 2 ? return o.length <= 1 + short ?
o o
// no short options -> offset first long option... // no short options -> offset first long option...
: i == 0 ? : 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... // add extra '-' to long options...
: '-'+ o }) : o.length > short ?
'-'+ o
: o })
.join(sep), .join(sep),
...(arg ? ...(arg ?
[arg] [arg]

View File

@ -1,6 +1,6 @@
{ {
"name": "ig-argv", "name": "ig-argv",
"version": "2.4.0", "version": "2.4.1",
"description": "simple argv parser", "description": "simple argv parser",
"main": "argv.js", "main": "argv.js",
"scripts": { "scripts": {

View File

@ -75,6 +75,9 @@ argv.Parser({
arg: 'STR | str', arg: 'STR | str',
collect: 'string|\t', collect: 'string|\t',
}, },
//'-a': '-ab',
'-sh': {
doc: 'short option', },
'-test': argv.Parser({ '-test': argv.Parser({