MCPcopy
hub / github.com/Kong/insomnia / addScriptCommand

Function addScriptCommand

packages/insomnia-inso/src/cli.ts:131–171  ·  view source on GitHub ↗
(originalCommand: commander.Command)

Source from the content-addressed store, hash-verified

129};
130
131const addScriptCommand = (originalCommand: commander.Command) => {
132 // inso script
133 originalCommand
134 .command('script <name>', {
135 isDefault: true,
136 })
137 .description('Run scripts defined in .insorc')
138 .allowUnknownOption()
139 // @ts-expect-error this appears to actually be valid, and I don't want to risk changing any behavior
140 .action((scriptName, cmd) => {
141 // Load scripts
142 let options = getOptions(cmd);
143 options = prepareCommand(options);
144
145 // Ignore the first arg because that will be scriptName, get the rest
146 const passThroughArgs = cmd.args.slice(1);
147
148 // Find script
149 const scriptTask = options.__configFile?.scripts?.[scriptName];
150
151 if (!scriptTask) {
152 logger.fatal(`Could not find inso script "${scriptName}" in the config file.`);
153 return exit(new Promise(resolve => resolve(false)));
154 }
155
156 if (!scriptTask.startsWith('inso')) {
157 logger.fatal('Tasks in a script should start with `inso`.');
158 return exit(new Promise(resolve => resolve(false)));
159 }
160
161 // Collect args
162 const scriptArgs: string[] = parseArgsStringToArgv(
163 `self ${scriptTask} ${passThroughArgs.join(' ')}`,
164 );
165
166 // Print command
167 logger.debug(`>> ${scriptArgs.slice(1).join(' ')}`); // Run
168
169 runWithArgs(originalCommand, scriptArgs);
170 });
171};
172
173export const go = (args?: string[], exitOverride?: boolean) => {
174 const commandCreator = (cmd?: string) => {

Callers 1

goFunction · 0.85

Calls 6

getOptionsFunction · 0.90
exitFunction · 0.90
prepareCommandFunction · 0.85
resolveFunction · 0.85
runWithArgsFunction · 0.85
commandMethod · 0.45

Tested by

no test coverage detected