Skip to content

Commit

Permalink
feat: init rm
Browse files Browse the repository at this point in the history
  • Loading branch information
Huy-DNA committed Nov 5, 2024
1 parent 21f4413 commit 143703d
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/command/impls/help.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ const commandDescriptions: Record<Command, CommandDescription> = {
{ args: ['(<oct><oct><oct>)?'] },
],
},
[Command.RM]: {
description: 'Remove files',
usages: [
{ args: ['<filename>+'] },
],
},
};

function getDescription(commandName: string): string[] {
Expand Down
12 changes: 12 additions & 0 deletions lib/command/impls/rm.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { fileService } from '~/services';
import { formatArg } from '../utils';
import type { CommandFunc } from './types';

export const rm: CommandFunc = async function(...args) {
// discard `rm`
args.shift();
// discard first space
args.shift();

return [];
};
1 change: 1 addition & 0 deletions lib/command/impls/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ export enum Command {
TOUCH = 'touch',
MKDIR = 'mkdir',
UMASK = 'umask',
RM = 'rm',
}
4 changes: 4 additions & 0 deletions lib/command/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { useradd } from './impls/useradd';
import { touch } from './impls/touch';
import { mkdir } from './impls/mkdir';
import { umask } from './impls/umask';
import { rm } from './impls/rm';

export async function execute(command: string): Promise<ColoredContent> {
const args = parse(command);
Expand Down Expand Up @@ -49,6 +50,9 @@ export async function execute(command: string): Promise<ColoredContent> {
case Command.UMASK:
res = await umask(...args as any);
break;
case Command.RM:
res = await rm(...args as any);
break;
default:
res = echo('echo', ' ', `Unknown command:\\u001b[31m ${args[0]}`);
break;
Expand Down

0 comments on commit 143703d

Please sign in to comment.