import type { CommandDescriptor, CommandOutput } from "@core/command"; import type { CommandIO } from "@core/command_io"; import { createErrorResult, createSuccessResult, type ResultSuccess } from "@core/result"; import { getCurrentSession } from "@core/session_manager"; import type { ShellState } from "@core/shell_state"; import type { InvalidArgumentsError, ShellError } from "@core/util/errors"; import { resolvePointer } from "@core/util/path_resolver"; export const COMMAND_NAME = "pwd"; //Need to implement escape sequences async function main(io: CommandIO, state: ShellState, args: string[]): Promise> { if (args.length > 0) { return { state, result: createErrorResult( "InvalidArguments", `Expected aruments 0, got ${args.length}.`, { expected: "pwd", actual: `pwd ${args.toString().replace(/[,]/g, " ")}` }, COMMAND_NAME, ), } satisfies CommandOutput; } const session = getCurrentSession(state); const path = resolvePointer(state, session.cwd); io.writeStdout(new TextEncoder().encode(path)); const result: ResultSuccess = createSuccessResult(COMMAND_NAME); return { state: state, result, }; } export const descriptor: CommandDescriptor = { fn: main, name: COMMAND_NAME, };