-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
55 additions
and
28 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* @flow */ | ||
|
||
import * as commands from './index.js'; | ||
import type {Reporter} from '../../reporters/index.js'; | ||
import type Config from '../../config.js'; | ||
import {sortAlpha, hyphenate} from '../../util/misc.js'; | ||
const chalk = require('chalk'); | ||
|
||
export function run( | ||
config: Config, | ||
reporter: Reporter, | ||
commander: Object, | ||
args: Array<string>, | ||
): Promise<void> { | ||
// ignore all arguments after a -- | ||
for (let i = 0; i < args.length; i++) { | ||
const arg = args[i]; | ||
if (arg === '--') { | ||
args = args.slice(0, i); | ||
} | ||
} | ||
|
||
const getDocsLink = (name) => `https://yarnpkg.com/en/docs/cli/${name || ''}`; | ||
const getDocsInfo = (name) => 'Visit ' + chalk.bold(getDocsLink(name)) + ' for documentation about this command.'; | ||
|
||
if (args.length) { | ||
const helpCommand = hyphenate(args[0]); | ||
if (commands[helpCommand]) { | ||
commander.on('--help', () => console.log(' ' + getDocsInfo(helpCommand) + '\n')); | ||
} | ||
} else { | ||
commander.on('--help', () => { | ||
console.log(' Commands:\n'); | ||
for (const name of Object.keys(commands).sort(sortAlpha)) { | ||
if (commands[name].useless) { | ||
continue; | ||
} | ||
|
||
console.log(` - ${hyphenate(name)}`); | ||
} | ||
console.log('\n Run `' + chalk.bold('yarn help COMMAND') + '` for more information on specific commands.'); | ||
console.log(' Visit ' + chalk.bold(getDocsLink()) + ' to learn more about Yarn.\n'); | ||
}); | ||
} | ||
commander.help(); | ||
return Promise.resolve(); | ||
} |
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