diff options
Diffstat (limited to 'lib/base-command.js')
-rw-r--r-- | lib/base-command.js | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/lib/base-command.js b/lib/base-command.js index 91c7c5357..322fd8963 100644 --- a/lib/base-command.js +++ b/lib/base-command.js @@ -4,6 +4,7 @@ const ConfigDefinitions = require('./utils/config/definitions.js') class BaseCommand { constructor (npm) { + this.wrapWidth = 80 this.npm = npm } @@ -27,8 +28,7 @@ class BaseCommand { usage = `${usage}${this.constructor.usage.map(u => `npm ${this.constructor.name} ${u}`).join('\n')}` if (this.constructor.params) - // TODO word wrap this along params boundaries - usage = `${usage}\n\nOptions:\n[${this.constructor.params.map(p => ConfigDefinitions[p].usage).join('] [')}]` + usage = `${usage}\n\nOptions:\n${this.wrappedParams}` // Mostly this just appends aliases, this could be more clear usage = usageUtil(this.constructor.name, usage) @@ -36,6 +36,22 @@ class BaseCommand { return usage } + get wrappedParams () { + let results = '' + let line = '' + + for (const param of this.constructor.params) { + const usage = `[${ConfigDefinitions[param].usage}]` + if (line.length && (line.length + usage.length) > this.wrapWidth) { + results = [results, line].filter(Boolean).join('\n') + line = '' + } + line = [line, usage].filter(Boolean).join(' ') + } + results = [results, line].filter(Boolean).join('\n') + return results + } + usageError (msg) { if (!msg) { return Object.assign(new Error(`\nUsage: ${this.usage}`), { |