-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(usage): clean up usage declarations
Small refactor of commands to allow usage to be more programmatically generated, leading us in the direction of more tighly coupling each command to the params it accepts. PR-URL: #2821 Credit: @wraithgar Close: #2821 Reviewed-by: @isaacs
- Loading branch information
Showing
84 changed files
with
1,023 additions
and
760 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// Base class for npm.commands[cmd] | ||
const usageUtil = require('./utils/usage.js') | ||
|
||
class BaseCommand { | ||
constructor (npm) { | ||
this.npm = npm | ||
} | ||
|
||
get usage () { | ||
let usage = `npm ${this.constructor.name}\n\n` | ||
if (this.constructor.description) | ||
usage = `${usage}${this.constructor.description}\n\n` | ||
|
||
usage = `${usage}Usage:\n` | ||
if (!this.constructor.usage) | ||
usage = `${usage}npm ${this.constructor.name}` | ||
else | ||
usage = `${usage}${this.constructor.usage.map(u => `npm ${this.constructor.name} ${u}`).join('\n')}` | ||
|
||
// Mostly this just appends aliases, this could be more clear | ||
usage = usageUtil(this.constructor.name, usage) | ||
usage = `${usage}\n\nRun "npm ${this.constructor.name} help" for more info` | ||
return usage | ||
} | ||
|
||
usageError (msg) { | ||
if (!msg) { | ||
return Object.assign(new Error(`\nUsage: ${this.usage}`), { | ||
code: 'EUSAGE', | ||
}) | ||
} | ||
|
||
return Object.assign(new Error(`\nUsage: ${msg}\n\n${this.usage}`), { | ||
code: 'EUSAGE', | ||
}) | ||
} | ||
} | ||
module.exports = BaseCommand |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.