import { Item } from '../fs/Item' import type { SimpleStream } from '../utils/SimpleStream' import { Program } from './Program' export class Rm extends Program { constructor() { super() } async Exec(_: SimpleStream, stdout: SimpleStream, workdir: Item, args: string[]): Promise { if (!args[1]) { stdout.emit("rm: error: missing first argument\n") return 1 } let item: Item try { item = await Item.openDir(args[1].startsWith('/') ? args[1] : `${workdir.GetPath()}${workdir.GetPath().endsWith('/') ? '' : '/'}${args[1]}`) } catch { item = await Item.open(args[1].startsWith('/') ? args[1] : `${workdir.GetPath()}${workdir.GetPath().endsWith('/') ? '' : '/'}${args[1]}`) } if (!(await item.Exists())) { stdout.emit(`rm: error: item ${item.GetPath()} doesn't exist.\n`) return 1 } stdout.emit(`-> removing: '${item.GetPath()}'\n`) await item.Delete() return 0 } }