29 lines
791 B
TypeScript
29 lines
791 B
TypeScript
import { Item } from '../fs/Item'
|
|
import type { SimpleStream } from '../utils/SimpleStream'
|
|
import { Program } from './Program'
|
|
|
|
export class Mkdir extends Program {
|
|
constructor() {
|
|
super()
|
|
}
|
|
|
|
async Exec(_: SimpleStream<string>, stdout: SimpleStream<string>, workdir: Item, args: string[]): Promise<number> {
|
|
if (args.length < 2) {
|
|
stdout.emit("mkdir: error: missing path argument\n")
|
|
return 1
|
|
}
|
|
|
|
const item = await Item.openDir(Item.NormalizePath(args[1].startsWith('/') ? args[1] : `${workdir.GetPath()}/${args[1]}`))
|
|
|
|
|
|
if (await item.Exists()) {
|
|
stdout.emit(`mkdir: directory ${item.GetPath()} already exists.\n`)
|
|
return 2
|
|
}
|
|
|
|
await item.Create()
|
|
|
|
return 0
|
|
}
|
|
}
|