ProzillaOS/packages/apps/terminal/core/commands/rm.ts
2024-06-16 21:46:44 +02:00

21 lines
No EOL
662 B
TypeScript

import { VirtualFile } from "../../../virtual-drive/file";
import { formatError } from "../_utils/terminal.utils";
import { Command, ExecuteParams } from "../command";
export const rm = new Command()
.setRequireArgs(true)
.setManual({
purpose: "Remove a file"
})
.setExecute(function(this: Command, args, params) {
const { currentDirectory } = params as ExecuteParams;
const fileId = (args as string[])[0];
const { name, extension } = VirtualFile.splitId(fileId);
const file = currentDirectory.findFile(name, extension);
if (!file)
return formatError(this.name, `${fileId}: No such file`);
file.delete();
return { blank: true };
});