chore: make webfs usable
This commit is contained in:
@@ -7,17 +7,24 @@ export class Echo extends Program {
|
||||
super()
|
||||
}
|
||||
|
||||
async Exec(_: SimpleStream<string>, stdout: SimpleStream<string>, ___: Item, args: string[]): Promise<number> {
|
||||
let item: Item = await Item.open(args[1])
|
||||
async Exec(_: SimpleStream<string>, stdout: SimpleStream<string>, workdir: Item, args: string[]): Promise<number> {
|
||||
if (args.length < 2) {
|
||||
stdout.emit("echo: error: missing path argument\n")
|
||||
return 1
|
||||
}
|
||||
|
||||
const item = await Item.open(args[1].startsWith('/')
|
||||
? args[1]
|
||||
: `${workdir.GetPath()}${workdir.GetPath().endsWith('/') ? '' : '/'}${args[1]}`)
|
||||
|
||||
if (!(await item.Exists())) {
|
||||
stdout.emit(`echo: error: item ${item.GetPath()} doesn't exist.\n`)
|
||||
return 1
|
||||
return 2
|
||||
}
|
||||
|
||||
if (item.IsDirectory()) {
|
||||
stdout.emit(`echo: error: can't write data to a directory; item ${item.GetPath()} is a directory.\n`)
|
||||
return 2
|
||||
return 3
|
||||
}
|
||||
|
||||
await item.Write(args.slice(2).join(' '))
|
||||
|
||||
Reference in New Issue
Block a user