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 TypeMethodDescriptionbooleancheckArgument(Object inputArgument) Checks if the given inputArgument is valid for this command.voidexecute()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:CommandBase method for show command name- Specified by:
getNamein interfaceCommandInterface- Specified by:
getNamein classCommand- Returns:
- command name
-
getDescr
Description copied from class:CommandBase method for show command description.- Specified by:
getDescrin interfaceCommandInterface- Specified by:
getDescrin 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:
executein interfaceCommandInterface- Specified by:
executein classCommand- Throws:
IllegalArgumentException
-
checkArgument
Description copied from class:CommandChecks if the given inputArgument is valid for this command.- Specified by:
checkArgumentin interfaceCommandInterface- Specified by:
checkArgumentin classCommand- Parameters:
inputArgument- the argument to check.- Returns:
- true if the argument is valid, false otherwise.
-