MCPcopy Create free account
hub / github.com/npm/cli / main

Function main

scripts/fish-completion.js:8–47  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

6const { definitions } = require('@npmcli/config/lib/definitions')
7
8async function main () {
9 const file = resolve(__dirname, '..', 'lib', 'utils', 'completion.fish')
10 console.log(await fs.readFile(file, 'utf-8'))
11 const cmds = {}
12 for (const cmd of commands) {
13 cmds[cmd] = { aliases: [cmd] }
14 const cmdClass = require(`../lib/commands/${cmd}.js`)
15 cmds[cmd].description = cmdClass.description
16 cmds[cmd].params = cmdClass.params
17 }
18 for (const alias in aliases) {
19 cmds[aliases[alias]].aliases.push(alias)
20 }
21 for (const cmd in cmds) {
22 console.log(`# ${cmd}`)
23 const { aliases: cmdAliases, description, params = [] } = cmds[cmd]
24 // If npm completion could return all commands in a fish friendly manner
25 // like we do w/ run-script these wouldn't be needed.
26 /* eslint-disable-next-line max-len */
27 console.log(`complete -x -c npm -n __fish_npm_needs_command -a '${cmdAliases.join(' ')}' -d '${description}'`)
28 const shorts = params.map(p => {
29 // Our multi-character short params (e.g. -ws) are not very standard and
30 // don't work with things that assume short params are only ever single
31 // characters.
32 if (definitions[p].short?.length === 1) {
33 return `-s ${definitions[p].short}`
34 }
35 }).filter(p => p).join(' ')
36 // The config descriptions are not appropriate for -d here. We may want to
37 // consider having a more terse description for these.
38 // We can also have a mechanism to auto-generate the long form of options
39 // that have predefined values.
40 // params completion
41 /* eslint-disable-next-line max-len */
42 console.log(`complete -x -c npm -n '__fish_seen_subcommand_from ${cmdAliases.join(' ')}' ${params.map(p => `-l ${p}`).join(' ')} ${shorts}`)
43 // builtin npm completion
44 /* eslint-disable-next-line max-len */
45 console.log(`complete -x -c npm -n '__fish_seen_subcommand_from ${cmdAliases.join(' ')}' -a '(__fish_complete_npm)'`)
46 }
47}
48
49main().then(() => {
50 return process.exit()

Callers 1

fish-completion.jsFile · 0.70

Calls 3

resolveFunction · 0.85
pushMethod · 0.80
filterMethod · 0.80

Tested by

no test coverage detected