-
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.
- Loading branch information
Showing
74 changed files
with
884 additions
and
757 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,35 @@ | ||
// Base class for npm.commands[cmd] | ||
const usageUtil = require('./utils/usage.js') | ||
|
||
class BaseCommand { | ||
constructor (npm) { | ||
this.npm = npm | ||
} | ||
|
||
get usage () { | ||
let usage = ` ${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')}` | ||
|
||
return usageUtil(this.constructor.name, 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.