[lib] now shell forbids to call any hidden commands from interactive mode or script mode

This commit is contained in:
tangxifan 2023-01-08 22:34:35 -08:00
parent da7153f031
commit aec592b27e
2 changed files with 15 additions and 4 deletions

View File

@ -206,8 +206,9 @@ class Shell {
void exit(const int& init_err = 0) const;
/* Execute a command, the command line is the user's input to launch a command
* The common_context is the data structure to exchange data between commands
* Optionally, hidden commands may be forbidden to call. User can allow them to be called under different situations
*/
int execute_command(const char* cmd_line, T& common_context);
int execute_command(const char* cmd_line, T& common_context, const bool& allow_hidden_command = true);
private: /* Internal data */
/* Name of the shell, this will appear in the interactive mode */

View File

@ -286,7 +286,8 @@ void Shell<T>::run_interactive_mode(T& context, const bool& quiet_mode) {
* Add to history
*/
if (strlen(cmd_line) > 0) {
execute_command((const char*)cmd_line, context);
/* Do not allow any hidden command to be directly called by users */
execute_command((const char*)cmd_line, context, false);
add_history(cmd_line);
}
@ -378,7 +379,8 @@ void Shell<T>::run_script_mode(const char* script_file_name,
/* Process the command only when the full command line in ended */
if (!cmd_line.empty()) {
VTR_LOG("\nCommand line to execute: %s\n", cmd_line.c_str());
int status = execute_command(cmd_line.c_str(), context);
/* Do not allow any hidden command to be directly called by users */
int status = execute_command(cmd_line.c_str(), context, false);
/* Empty the line ready to start a new line */
cmd_line.clear();
@ -507,7 +509,7 @@ void Shell<T>::exit(const int& init_err) const {
***********************************************************************/
template <class T>
int Shell<T>::execute_command(const char* cmd_line,
T& common_context) {
T& common_context, const bool& allow_hidden_command) {
openfpga::StringToken tokenizer(cmd_line);
tokenizer.add_delim(' ');
/* Do not split the string in each quote "", as they should be a piece */
@ -537,6 +539,14 @@ int Shell<T>::execute_command(const char* cmd_line,
tokens[0].c_str());
return CMD_EXEC_FATAL_ERROR;
}
/* Do not allow hidden commands if specified */
if (!allow_hidden_command) {
if (command_hidden_[cmd_id]) {
VTR_LOG("Try to call a command '%s' which is not defined!\n",
tokens[0].c_str());
return CMD_EXEC_FATAL_ERROR;
}
}
/* Check the dependency graph to see if all the prequistics have been met */
for (const ShellCommandId& dep_cmd : command_dependencies_[cmd_id]) {