feat: working filesystem
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
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<string>, stdout: SimpleStream<string>, workdir: Item, args: string[]): Promise<number> {
|
||||
if (!args[1]) {
|
||||
stdout.emit("rm: error: missing first argument\n")
|
||||
return 1
|
||||
}
|
||||
|
||||
let item: Item
|
||||
|
||||
try {
|
||||
item = await Item.openDir(args[1])
|
||||
} catch {
|
||||
item = await Item.open(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
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user