[lib] now shell forbids to call any hidden commands from interactive mode or script mode
This commit is contained in:
parent
da7153f031
commit
aec592b27e
|
@ -206,8 +206,9 @@ class Shell {
|
||||||
void exit(const int& init_err = 0) const;
|
void exit(const int& init_err = 0) const;
|
||||||
/* Execute a command, the command line is the user's input to launch a command
|
/* 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
|
* 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 */
|
private: /* Internal data */
|
||||||
/* Name of the shell, this will appear in the interactive mode */
|
/* Name of the shell, this will appear in the interactive mode */
|
||||||
|
|
|
@ -286,7 +286,8 @@ void Shell<T>::run_interactive_mode(T& context, const bool& quiet_mode) {
|
||||||
* Add to history
|
* Add to history
|
||||||
*/
|
*/
|
||||||
if (strlen(cmd_line) > 0) {
|
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);
|
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 */
|
/* Process the command only when the full command line in ended */
|
||||||
if (!cmd_line.empty()) {
|
if (!cmd_line.empty()) {
|
||||||
VTR_LOG("\nCommand line to execute: %s\n", cmd_line.c_str());
|
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 */
|
/* Empty the line ready to start a new line */
|
||||||
cmd_line.clear();
|
cmd_line.clear();
|
||||||
|
|
||||||
|
@ -507,7 +509,7 @@ void Shell<T>::exit(const int& init_err) const {
|
||||||
***********************************************************************/
|
***********************************************************************/
|
||||||
template <class T>
|
template <class T>
|
||||||
int Shell<T>::execute_command(const char* cmd_line,
|
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);
|
openfpga::StringToken tokenizer(cmd_line);
|
||||||
tokenizer.add_delim(' ');
|
tokenizer.add_delim(' ');
|
||||||
/* Do not split the string in each quote "", as they should be a piece */
|
/* 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());
|
tokens[0].c_str());
|
||||||
return CMD_EXEC_FATAL_ERROR;
|
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 */
|
/* Check the dependency graph to see if all the prequistics have been met */
|
||||||
for (const ShellCommandId& dep_cmd : command_dependencies_[cmd_id]) {
|
for (const ShellCommandId& dep_cmd : command_dependencies_[cmd_id]) {
|
||||||
|
|
Loading…
Reference in New Issue