feat: working filesystem
This commit is contained in:
@@ -8,15 +8,24 @@ export class Ls extends Program {
|
||||
}
|
||||
|
||||
async Exec(_: SimpleStream<string>, stdout: SimpleStream<string>, workdir: Item, args: string[]): Promise<number> {
|
||||
if (!(new Item(args[1]).IsDirectory())) {
|
||||
stdout.emit("ls: error: the provided path is not a directory")
|
||||
let item: Item = args[1] ? await Item.openDir(args[1]) : workdir
|
||||
if (args[1] && !item.IsDirectory()) {
|
||||
stdout.emit("ls: error: the provided path is not a directory\n")
|
||||
return 1
|
||||
}
|
||||
|
||||
stdout.emit(`item: '${workdir.GetPath()}'\n`)
|
||||
stdout.emit(`index attr name\n`)
|
||||
workdir.List().forEach((entry, i) => {
|
||||
stdout.emit(`${i.toString().padEnd(8, ' ')} ${''.padEnd(4, '-').padEnd(8, ' ')} '${entry.GetName()}'\n`)
|
||||
if (!(await item.Exists())) {
|
||||
stdout.emit(`ls: error: path ${item.GetPath()} doesn't exist\n`)
|
||||
return 2
|
||||
}
|
||||
|
||||
console.log(item)
|
||||
|
||||
stdout.emit(`-> Listing contents of item: '${item.GetPath()}'\n`)
|
||||
stdout.emit(` [ attr name ]\n`)
|
||||
const items = await item.List()
|
||||
items.forEach((entry, i) => {
|
||||
stdout.emit(` | ${''.padEnd(4, '-').padEnd(8, ' ')} ${entry.GetName()}\n`)
|
||||
})
|
||||
|
||||
return 0
|
||||
|
||||
Reference in New Issue
Block a user