34 lines
956 B
TypeScript
34 lines
956 B
TypeScript
import type { CommandDescriptor, CommandOutput } from "@core/command";
|
|
import type { ResultSuccess } from "@core/result";
|
|
import type { ShellState } from "@core/shell_state";
|
|
import type { ShellError } from "@core/util/errors";
|
|
import { createImmutableBuffer } from "@core/util/immutable_buffer";
|
|
|
|
export const COMMAND_NAME = "echo";
|
|
|
|
//Need to implement escape sequences
|
|
function main(state: ShellState, flags: string[], args: string[]): CommandOutput<ShellError> {
|
|
const joined = args.join(" ");
|
|
const encoded = new TextEncoder().encode(joined);
|
|
|
|
const stdout = createImmutableBuffer(encoded);
|
|
|
|
const result: ResultSuccess = {
|
|
type: "success",
|
|
exitCode: 0,
|
|
stdout,
|
|
stderr: createImmutableBuffer(new Uint8Array()),
|
|
commandName: COMMAND_NAME,
|
|
};
|
|
|
|
return {
|
|
state: state,
|
|
result,
|
|
};
|
|
}
|
|
|
|
export const descriptor: CommandDescriptor = {
|
|
fn: main,
|
|
name: COMMAND_NAME,
|
|
};
|