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

Function runInitializeCommand

src/spec-node/utils.ts:533–617  ·  view source on GitHub ↗
(params: DockerResolverParameters, userCommand: LifecycleCommand | undefined, onDidInput?: Event<string>)

Source from the content-addressed store, hash-verified

531}
532
533export async function runInitializeCommand(params: DockerResolverParameters, userCommand: LifecycleCommand | undefined, onDidInput?: Event<string>) {
534 if (!userCommand) {
535 return;
536 }
537
538 let hasCommand = false;
539 if (typeof userCommand === 'string') {
540 hasCommand = userCommand.trim().length > 0;
541 } else if (Array.isArray(userCommand)) {
542 hasCommand = userCommand.length > 0;
543 } else if (typeof userCommand === 'object') {
544 hasCommand = Object.keys(userCommand).length > 0;
545 }
546
547 if (!hasCommand) {
548 return;
549 }
550
551 const { common, dockerEnv } = params;
552 const { cliHost, output } = common;
553 const hookName = 'initializeCommand';
554 const isWindows = cliHost.platform === 'win32';
555 const shell = isWindows ? [cliHost.env.ComSpec || 'cmd.exe', '/c'] : ['/bin/sh', '-c'];
556
557 const infoOutput = makeLog(output, LogLevel.Info);
558
559 try {
560 // Runs a command.
561 // Useful for the object syntax, where >1 command can be specified to run in parallel.
562 async function runSingleCommand(command: string | string[], name?: string) {
563 const updatedCommand = isWindows && Array.isArray(command) && command.length ?
564 [(command[0] || '').replace(/\//g, '\\'), ...command.slice(1)] :
565 command;
566 const args = typeof updatedCommand === 'string' ? [...shell, updatedCommand] : updatedCommand;
567 if (!args.length) {
568 return;
569 }
570
571 // 'name' is set when parallel execution syntax is used.
572 if (name) {
573 infoOutput.raw(`\x1b[1mRunning '${name}' from ${hookName}...\x1b[0m\r\n\r\n`);
574 } else {
575 infoOutput.raw(`\x1b[1mRunning the ${hookName} from devcontainer.json...\x1b[0m\r\n\r\n`);
576 }
577
578 // If we have a command name then the command is running in parallel and
579 // we need to hold output until the command is done so that the output
580 // doesn't get interleaved with the output of other commands.
581 const print = name ? 'end' : 'continuous';
582
583 await runCommand({
584 ptyExec: cliHost.ptyExec,
585 cmd: args[0],
586 args: args.slice(1),
587 env: dockerEnv,
588 output: infoOutput,
589 onDidInput,
590 print,

Callers 1

resolveWithLocalFolderFunction · 0.90

Calls 3

makeLogFunction · 0.90
rawMethod · 0.80
runSingleCommandFunction · 0.70

Tested by

no test coverage detected