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:
Diffstat (limited to 'lib/help-search.js')
-rw-r--r--lib/help-search.js24
1 files changed, 7 insertions, 17 deletions
diff --git a/lib/help-search.js b/lib/help-search.js
index 62e1adb59..c1ceae441 100644
--- a/lib/help-search.js
+++ b/lib/help-search.js
@@ -1,15 +1,16 @@
const fs = require('fs')
const path = require('path')
const color = require('ansicolors')
-const npmUsage = require('./utils/npm-usage.js')
const { promisify } = require('util')
const glob = promisify(require('glob'))
const readFile = promisify(fs.readFile)
-const didYouMean = require('./utils/did-you-mean.js')
-const { cmdList } = require('./utils/cmd-list.js')
const BaseCommand = require('./base-command.js')
class HelpSearch extends BaseCommand {
+ static get description () {
+ return 'Search npm help documentation'
+ }
+
/* istanbul ignore next - see test/lib/load-all-commands.js */
static get name () {
return 'help-search'
@@ -26,28 +27,17 @@ class HelpSearch extends BaseCommand {
async helpSearch (args) {
if (!args.length)
- throw this.usage
+ return this.npm.output(this.usage)
const docPath = path.resolve(__dirname, '..', 'docs/content')
-
const files = await glob(`${docPath}/*/*.md`)
const data = await this.readFiles(files)
const results = await this.searchFiles(args, data, files)
- // if only one result, then just show that help section.
- if (results.length === 1) {
- return this.npm.commands.help([path.basename(results[0].file, '.md')], er => {
- if (er)
- throw er
- })
- }
-
const formatted = this.formatResults(args, results)
if (!formatted.trim())
- npmUsage(this.npm, false)
- else {
+ this.npm.output(`No matches in help for: ${args.join(' ')}\n`)
+ else
this.npm.output(formatted)
- this.npm.output(didYouMean(args[0], cmdList))
- }
}
async readFiles (files) {