Skip to content

Commit

Permalink
show >dice after entering blocklisted command
Browse files Browse the repository at this point in the history
  • Loading branch information
helios2003 committed Jan 2, 2025
1 parent ee239ef commit 1bdc5e2
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
7 changes: 2 additions & 5 deletions apps/playground-web/components/Shell/hooks/useShell.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { useState, useEffect, useRef, KeyboardEvent, ChangeEvent } from 'react';

// utils
import { handleCommand } from '@/shared/utils/shellUtils';
import { handleCommand, handleInvalidCommand } from '@/shared/utils/shellUtils';
import blocklistedCommands from '@/shared/utils/blocklist';

export const useShell = (
Expand All @@ -29,10 +29,7 @@ export const useShell = (
}

if (blocklistedCommands.includes(commandName)) {
setOutput((prevOutput) => [
...prevOutput,
`(error) ERR unknown command '${commandName}'`,
]);
handleInvalidCommand({ command, setOutput });
} else {
handleCommand({ command, setOutput, onCommandExecuted }); // Execute if not blocklisted
}
Expand Down
14 changes: 13 additions & 1 deletion apps/playground-web/shared/utils/shellUtils.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
// src/shared/utils/shellUtils.ts

import { executeShellCommandOnServer } from '@/lib/api';
import { CommandHandler } from '@/types';
import { CommandHandler, InvalidCommandHandler } from '@/types';
import { handleResult } from '@/shared/utils/commonUtils';

export const handleInvalidCommand = async ({
command,
setOutput
}: InvalidCommandHandler) => {
const newOutput = `dice > ${command}`;
setOutput((prevOutput: any) => [

Check warning on line 12 in apps/playground-web/shared/utils/shellUtils.ts

View workflow job for this annotation

GitHub Actions / Build and Test

Unexpected any. Specify a different type
...prevOutput,
newOutput,
`(error) ERR unknown command '${command}'`,
]);
}

export const handleCommand = async ({
command,
setOutput,
Expand Down
5 changes: 5 additions & 0 deletions apps/playground-web/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,8 @@ export interface CommandHandler {
setOutput: React.Dispatch<React.SetStateAction<string[]>>;
onCommandExecuted: (commandsLeft: number, cleanupTimeLeft: number) => void;
}

export interface InvalidCommandHandler {
command: string;
setOutput: React.Dispatch<React.SetStateAction<string[]>>;
}

0 comments on commit 1bdc5e2

Please sign in to comment.