Package core
Class CommandHandler
java.lang.Object
core.CommandHandler
Central class responsible for parsing user input, handling command execution (builtins and
external), managing pipelines, redirection, and maintaining the current working directory.
-
Constructor Summary
ConstructorsConstructorDescriptionConstructs a CommandHandler, initializing all built-in commands, the command history, and setting the current working directory to the user's directory. -
Method Summary
Modifier and TypeMethodDescriptiongetCommand(String[] tokens, String rawInput, File redirectFile, File stderrRedirectFile) Returns the appropriate Command instance (builtin or external) for the given tokens.Returns the history of commands.handleCommand(String input, Path currentDirectory) Parses and executes a single shell command or pipeline, handling redirection and updating the current directory as needed.
-
Constructor Details
-
CommandHandler
public CommandHandler()Constructs a CommandHandler, initializing all built-in commands, the command history, and setting the current working directory to the user's directory.
-
-
Method Details
-
handleCommand
Parses and executes a single shell command or pipeline, handling redirection and updating the current directory as needed.- Parameters:
input- The command line input string.currentDirectory- The current working directory.- Returns:
- The updated current directory after command execution.
-
getCommand
public Command getCommand(String[] tokens, String rawInput, File redirectFile, File stderrRedirectFile) Returns the appropriate Command instance (builtin or external) for the given tokens.- Parameters:
tokens- The command and its arguments.rawInput- The raw input string.redirectFile- Output redirection file, if any.stderrRedirectFile- Error redirection file, if any.- Returns:
- The Command instance to execute.
-
getHistory
Returns the history of commands.- Returns:
- The list of previous commands entered by the user.
-