- initial changes to data shapes
- ls command needs fixing
This commit is contained in:
+12
-19
@@ -5,7 +5,7 @@ import { withExitCode, withHistory, type ShellState } from "@core/shell_state";
|
||||
import { SIGNAL_MAP } from "@core/signal";
|
||||
import type { ShellError } from "@core/util/errors";
|
||||
import { createImmutableBuffer } from "@core/util/immutable_buffer";
|
||||
import { parseCommand } from "@core/util/parser";
|
||||
import { tokenize } from "@core/util/parser";
|
||||
import { EventEmitter } from "./event_emitter";
|
||||
import { ProcessManager } from "./process_manager";
|
||||
|
||||
@@ -64,30 +64,21 @@ export class Shell {
|
||||
}
|
||||
|
||||
public async execute(input: string): Promise<void> {
|
||||
let parsed;
|
||||
try {
|
||||
parsed = parseCommand(input);
|
||||
} catch {
|
||||
const result = createErrorResult("ParseError", `Parsing error - ${input}`, {});
|
||||
const parsed = tokenize(input);
|
||||
|
||||
this._State = withExitCode(this._State, result.error.exitCode);
|
||||
this._EventEmitter.emit("result", { pid: 0, result, state: this._State });
|
||||
return;
|
||||
}
|
||||
|
||||
if (parsed.command === "") return;
|
||||
if (!parsed[0]) return;
|
||||
|
||||
this._State = withHistory(this._State, input);
|
||||
const command = COMMAND_REGISTRY.get(parsed.command);
|
||||
const command = COMMAND_REGISTRY.get(parsed[0]);
|
||||
|
||||
if (!command) {
|
||||
const encoded = new TextEncoder().encode(`Command ${parsed.command} not found`);
|
||||
const encoded = new TextEncoder().encode(`Command ${parsed[0]} not found`);
|
||||
|
||||
const result = createErrorResult(
|
||||
"CommandNotFound",
|
||||
`Command ${parsed.command} not found`,
|
||||
{ command: parsed.command },
|
||||
parsed.command,
|
||||
`Command ${parsed[0]} not found`,
|
||||
{ command: parsed[0] },
|
||||
parsed[0],
|
||||
createImmutableBuffer(encoded),
|
||||
createImmutableBuffer(new Uint8Array()),
|
||||
);
|
||||
@@ -102,7 +93,7 @@ export class Shell {
|
||||
"PermissionDenied",
|
||||
`Permission Denied`,
|
||||
{ resource: `Execution of the ${command.name} command` },
|
||||
parsed.command,
|
||||
parsed[0],
|
||||
);
|
||||
|
||||
this._State = withExitCode(this._State, result.error.exitCode);
|
||||
@@ -110,7 +101,9 @@ export class Shell {
|
||||
return;
|
||||
}
|
||||
|
||||
const pid = this._ProcessManager.createProcess(this._State, command, parsed.flags, parsed.args);
|
||||
parsed.shift();
|
||||
|
||||
const pid = this._ProcessManager.createProcess(this._State, command, parsed);
|
||||
this.BoundPID = pid;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user