Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGar <gar+gh@danger.computer>2021-04-08 20:08:23 +0300
committerGar <gar+gh@danger.computer>2021-04-15 20:30:37 +0300
commit8c9e24778db867cb3148bc247c7e321639aa9f58 (patch)
tree70b5db93056e1dc0b0542d88d348c5a8107213fd /lib/base-command.js
parent3b476a24cf0b2823fdf92505b84bddde4fcc8b14 (diff)
feat(version): add workspace support
PR-URL: https://github.com/npm/cli/pull/3055 Credit: @wraithgar Close: #3055 Reviewed-by: @darcyclarke
Diffstat (limited to 'lib/base-command.js')
-rw-r--r--lib/base-command.js20
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}`), {