MCPcopy Index your code
hub / github.com/open-cli-tools/concurrently / handle

Method handle

lib/flow-control/input-handler.ts:43–94  ·  view source on GitHub ↗
(commands: Command[])

Source from the content-addressed store, hash-verified

41 }
42
43 handle(commands: Command[]): {
44 commands: Command[];
45 onFinish?: () => void | undefined;
46 } {
47 const { inputStream } = this;
48 if (!inputStream) {
49 return { commands };
50 }
51
52 const commandsMap = new Map<string, Command>();
53 for (const command of commands) {
54 commandsMap.set(command.index.toString(), command);
55 commandsMap.set(command.name, command);
56 }
57
58 Rx.fromEvent(inputStream, 'data')
59 .pipe(map((data) => String(data)))
60 .subscribe((data) => {
61 const dataParts = data.split(/:(.+)/s);
62 let target = dataParts[0];
63 let command = commandsMap.get(target);
64 let input: string;
65
66 if (dataParts.length > 1 && command) {
67 input = dataParts[1];
68 } else {
69 // If `target` does not match a registered command,
70 // fallback to `defaultInputTarget` and forward the whole input data
71 target = this.defaultInputTarget.toString();
72 command = commandsMap.get(target);
73 input = data;
74 }
75
76 if (command?.stdin) {
77 command.stdin.write(input);
78 } else {
79 this.logger.logGlobalEvent(
80 `Unable to find command "${target}", or it has no stdin open\n`,
81 );
82 }
83 });
84
85 return {
86 commands,
87 onFinish: () => {
88 if (this.pauseInputStreamOnFinish) {
89 // https://github.com/kimmobrunfeldt/concurrently/issues/252
90 inputStream.pause();
91 }
92 },
93 };
94 }
95}

Callers

nothing calls this directly

Calls 3

logGlobalEventMethod · 0.80
getMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected