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

Function runLifecycleCommand

src/spec-common/injectHeadless.ts:465–572  ·  view source on GitHub ↗
({ lifecycleHook }: ResolverParameters, containerProperties: ContainerProperties, userCommand: LifecycleCommand, userCommandOrigin: string, lifecycleHookName: 'onCreateCommand' | 'updateContentCommand' | 'postCreateCommand' | 'postStartCommand' | 'postAttachCommand', remoteEnv: Promise<Record<string, string>>, secrets: Promise<Record<string, string>>, doRun: boolean)

Source from the content-addressed store, hash-verified

463}
464
465async function runLifecycleCommand({ lifecycleHook }: ResolverParameters, containerProperties: ContainerProperties, userCommand: LifecycleCommand, userCommandOrigin: string, lifecycleHookName: 'onCreateCommand' | 'updateContentCommand' | 'postCreateCommand' | 'postStartCommand' | 'postAttachCommand', remoteEnv: Promise<Record<string, string>>, secrets: Promise<Record<string, string>>, doRun: boolean) {
466 let hasCommand = false;
467 if (typeof userCommand === 'string') {
468 hasCommand = userCommand.trim().length > 0;
469 } else if (Array.isArray(userCommand)) {
470 hasCommand = userCommand.length > 0;
471 } else if (typeof userCommand === 'object') {
472 hasCommand = Object.keys(userCommand).length > 0;
473 }
474 if (doRun && userCommand && hasCommand) {
475 const progressName = `Running ${lifecycleHookName}...`;
476 const infoOutput = makeLog({
477 event(e: LogEvent) {
478 lifecycleHook.output.event(e);
479 if (e.type === 'raw' && e.text.includes('::endstep::')) {
480 lifecycleHook.output.event({
481 type: 'progress',
482 name: progressName,
483 status: 'running',
484 stepDetail: ''
485 });
486 }
487 if (e.type === 'raw' && e.text.includes('::step::')) {
488 lifecycleHook.output.event({
489 type: 'progress',
490 name: progressName,
491 status: 'running',
492 stepDetail: `${e.text.split('::step::')[1].split('\r\n')[0]}`
493 });
494 }
495 },
496 get dimensions() {
497 return lifecycleHook.output.dimensions;
498 },
499 onDidChangeDimensions: lifecycleHook.output.onDidChangeDimensions,
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) {

Callers 1

runLifecycleCommandsFunction · 0.85

Calls 4

makeLogFunction · 0.90
rawMethod · 0.80
runSingleCommandFunction · 0.70
eventMethod · 0.65

Tested by

no test coverage detected