Package commandManagers.commands
Class ExecuteScript
java.lang.Object
commandManagers.Command
commandManagers.commands.ExecuteScript
- All Implemented Interfaces:
CommandInterface
ExecuteScript is a class that represents the execute_script command.
It reads and executes a script from a file that contains a sequence of commands and arguments.
It also prevents recursion by keeping track of file paths that have already been executed.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionboolean
checkArgument
(Object inputArgument) Checks if the given inputArgument is valid for this command.void
execute()
Executes the command by reading and parsing the script file.getDescr()
Base method for show command description.getName()
Base method for show command nameMethods inherited from class commandManagers.Command
getArgument, isHasArgument, setArgument
-
Constructor Details
-
ExecuteScript
public ExecuteScript()Constructs a new ExecuteScript object. Initializes commandMap with the command map from CommandManager, and creates an empty ArrayList of filePaths.
-
-
Method Details
-
getName
Description copied from class:Command
Base method for show command name- Specified by:
getName
in interfaceCommandInterface
- Specified by:
getName
in classCommand
- Returns:
- command name
-
getDescr
Description copied from class:Command
Base method for show command description.- Specified by:
getDescr
in interfaceCommandInterface
- Specified by:
getDescr
in classCommand
- Returns:
- command description
-
execute
Executes the command by reading and parsing the script file. Each command in the file is executed using its corresponding command object from the command map. The method also checks for recursion by ensuring that a file path is not executed twice.- Specified by:
execute
in interfaceCommandInterface
- Specified by:
execute
in classCommand
- Throws:
IllegalArgumentException
-
checkArgument
Description copied from class:Command
Checks if the given inputArgument is valid for this command.- Specified by:
checkArgument
in interfaceCommandInterface
- Specified by:
checkArgument
in classCommand
- Parameters:
inputArgument
- the argument to check.- Returns:
- true if the argument is valid, false otherwise.
-