Merge pull request #986 from lnis-uofu/hide_cmd
Now hidden commands are not allowed to be called through interactive mode and script model in OpenFPGA shell
This commit is contained in:
commit
0e4d5fdd29
|
@ -206,8 +206,11 @@ 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();
|
||||||
|
|
||||||
|
@ -420,13 +422,13 @@ void Shell<T>::print_commands(const bool& show_hidden) const {
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Print the class name */
|
/* Print the class name */
|
||||||
if (show_hidden && hidden_class) {
|
if (!show_hidden && hidden_class) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
VTR_LOG("%s:\n", command_class_names_[cmd_class].c_str());
|
VTR_LOG("%s:\n", command_class_names_[cmd_class].c_str());
|
||||||
|
|
||||||
for (const ShellCommandId& cmd : commands_by_classes_[cmd_class]) {
|
for (const ShellCommandId& cmd : commands_by_classes_[cmd_class]) {
|
||||||
if (show_hidden && command_hidden_[cmd]) {
|
if (!show_hidden && command_hidden_[cmd]) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
VTR_LOG("\t%s\n", commands_[cmd].name().c_str());
|
VTR_LOG("\t%s\n", commands_[cmd].name().c_str());
|
||||||
|
@ -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