MCPcopy Index your code
hub / github.com/devcontainers/cli / runSingleCommand

Function runSingleCommand

src/spec-common/injectHeadless.ts:502–538  ·  view source on GitHub ↗
(postCommand: string | string[], name?: string)

Source from the content-addressed store, hash-verified

500 }, LogLevel.Info);
501 const remoteCwd = containerProperties.remoteWorkspaceFolder || containerProperties.homeFolder;
502 async function runSingleCommand(postCommand: string | string[], name?: string) {
503 const progressDetails = typeof postCommand === 'string' ? postCommand : postCommand.join(' ');
504 infoOutput.event({
505 type: 'progress',
506 name: progressName,
507 status: 'running',
508 stepDetail: progressDetails
509 });
510 // If we have a command name then the command is running in parallel and
511 // we need to hold output until the command is done so that the output
512 // doesn't get interleaved with the output of other commands.
513 const printMode = name ? 'off' : 'continuous';
514 const env = { ...(await remoteEnv), ...(await secrets) };
515 try {
516 const { cmdOutput } = await runRemoteCommand({ ...lifecycleHook, output: infoOutput }, containerProperties, typeof postCommand === 'string' ? ['/bin/sh', '-c', postCommand] : postCommand, remoteCwd, { remoteEnv: env, pty: true, print: printMode });
517
518 // 'name' is set when parallel execution syntax is used.
519 if (name) {
520 infoOutput.raw(`\x1b[1mRunning ${name} of ${lifecycleHookName} from ${userCommandOrigin}...\x1b[0m\r\n${cmdOutput}\r\n`);
521 }
522 } catch (err) {
523 if (printMode === 'off' && err?.cmdOutput) {
524 infoOutput.raw(`\r\n\x1b[1m${err.cmdOutput}\x1b[0m\r\n\r\n`);
525 }
526 if (err && (err.code === 130 || err.signal === 2)) { // SIGINT seen on darwin as code === 130, would also make sense as signal === 2.
527 infoOutput.raw(`\r\n\x1b[1m${name ? `${name} of ${lifecycleHookName}` : lifecycleHookName} from ${userCommandOrigin} interrupted.\x1b[0m\r\n\r\n`);
528 } else {
529 if (err?.code) {
530 infoOutput.write(toErrorText(`${name ? `${name} of ${lifecycleHookName}` : lifecycleHookName} from ${userCommandOrigin} failed with exit code ${err.code}. Skipping any further user-provided commands.`));
531 }
532 throw new ContainerError({
533 description: `${name ? `${name} of ${lifecycleHookName}` : lifecycleHookName} from ${userCommandOrigin} failed.`,
534 originalError: err
535 });
536 }
537 }
538 }
539
540 infoOutput.raw(`\x1b[1mRunning the ${lifecycleHookName} from ${userCommandOrigin}...\x1b[0m\r\n\r\n`);
541

Callers 1

runLifecycleCommandFunction · 0.70

Calls 5

runRemoteCommandFunction · 0.85
toErrorTextFunction · 0.85
rawMethod · 0.80
eventMethod · 0.65
writeMethod · 0.65

Tested by

no test coverage detected