MCPcopy
hub / github.com/Cveinnt/LiveTerm / shell

Function shell

src/utils/shell.ts:4–27  ·  view source on GitHub ↗
(
  command: string,
  setHistory: (value: string) => void,
  clearHistory: () => void,
  setCommand: React.Dispatch<React.SetStateAction<string>>,
)

Source from the content-addressed store, hash-verified

2import * as bin from './bin';
3
4export const shell = async (
5 command: string,
6 setHistory: (value: string) => void,
7 clearHistory: () => void,
8 setCommand: React.Dispatch<React.SetStateAction<string>>,
9) => {
10 const args = command.split(' ');
11 args[0] = args[0].toLowerCase();
12
13 if (args[0] === 'clear') {
14 clearHistory();
15 } else if (command === '') {
16 setHistory('');
17 } else if (Object.keys(bin).indexOf(args[0]) === -1) {
18 setHistory(
19 `shell: command not found: ${args[0]}. Try 'help' to get started.`,
20 );
21 } else {
22 const output = await bin[args[0]](args.slice(1));
23 setHistory(output);
24 }
25
26 setCommand('');
27};

Callers 1

onSubmitFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected