MCPcopy
hub / github.com/dotenvx/dotenvx / executeDynamic

Function executeDynamic

src/lib/helpers/executeDynamic.js:62–102  ·  view source on GitHub ↗
(program, command, rawArgs)

Source from the content-addressed store, hash-verified

60}
61
62function executeDynamic (program, command, rawArgs) {
63 if (!command) {
64 program.outputHelp()
65 process.exit(1)
66 return
67 }
68
69 // construct the full command line manually including flags
70 const commandIndex = rawArgs.indexOf(command)
71 const forwardedArgs = rawArgs.slice(commandIndex + 1)
72
73 logger.debug(`command: ${command}`)
74 logger.debug(`args: ${JSON.stringify(forwardedArgs)}`)
75
76 const binPath = path.join(process.cwd(), 'node_modules', '.bin')
77 const newPath = `${binPath}:${process.env.PATH}`
78 const env = { ...process.env, PATH: newPath }
79
80 const spawnOptions = { stdio: 'inherit', env }
81 let result
82 for (const [spawnCommand, spawnArgs] of dynamicAttempts(command, forwardedArgs)) {
83 result = childProcess.spawnSync(spawnCommand, spawnArgs, spawnOptions)
84 if (!result.error) break
85 }
86
87 if (result.error) {
88 if (command === 'vlt') {
89 console.log(armorBanner())
90 } else if (command === 'ops') {
91 console.log(armorBanner())
92 } else if (command === 'armor') {
93 console.log(armorBanner())
94 } else {
95 logger.info(`error: unknown command '${command}'`)
96 }
97 }
98
99 if (result.status !== 0) {
100 process.exit(result.status)
101 }
102}
103
104module.exports = executeDynamic

Callers 3

dotenvx.jsFile · 0.85
configureArmorCommandFunction · 0.85

Calls 2

dynamicAttemptsFunction · 0.85
armorBannerFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…