MCPcopy Index your code
hub / github.com/nodejs/node / exec

Method exec

deps/npm/lib/commands/help.js:46–76  ·  view source on GitHub ↗
(args)

Source from the content-addressed store, hash-verified

44 }
45
46 async exec (args) {
47 // By default we search all of our man subdirectories, but if the user has asked for a specific one we limit the search to just there
48 const manSearch = /^\d+$/.test(args[0]) ? `man${args.shift()}` : 'man*'
49
50 if (!args.length) {
51 return output.standard(this.npm.usage)
52 }
53
54 // npm help foo bar baz: search topics
55 if (args.length > 1) {
56 return this.helpSearch(args)
57 }
58
59 // `npm help package.json`
60 const arg = (deref(args[0]) || args[0]).replace('.json', '-json')
61
62 // find either section.n or npm-section.n
63 const f = globify(path.resolve(this.npm.npmRoot, `man/${manSearch}/?(npm-)${arg}.[0-9]*`))
64
65 const [man] = await glob(f).then(r => r.sort((a, b) => {
66 // Because the glob is (subtly) different from manNumberRegex, we can't rely on it passing.
67 const aManNumberMatch = a.match(manNumberRegex)?.[1] || 999
68 const bManNumberMatch = b.match(manNumberRegex)?.[1] || 999
69 if (aManNumberMatch !== bManNumberMatch) {
70 return aManNumberMatch - bManNumberMatch
71 }
72 return localeCompare(a, b)
73 }))
74
75 return man ? this.viewMan(man) : this.helpSearch(args)
76 }
77
78 helpSearch (args) {
79 return this.npm.exec('help-search', args)

Callers 1

helpSearchMethod · 0.45

Calls 11

helpSearchMethod · 0.95
viewManMethod · 0.95
derefFunction · 0.85
sortMethod · 0.80
globifyFunction · 0.70
matchMethod · 0.65
globFunction · 0.50
testMethod · 0.45
shiftMethod · 0.45
resolveMethod · 0.45
thenMethod · 0.45

Tested by

no test coverage detected