[Tool] Enhance return code for openfpga shell
This commit is contained in:
parent
8cac3291cb
commit
fd0e73a9bb
|
@ -148,6 +148,10 @@ class Shell {
|
|||
const bool& batch_mode = false);
|
||||
/* Print all the commands by their classes. This is actually the help desk */
|
||||
void print_commands() const;
|
||||
/* Find the exit code (assume quit shell now) */
|
||||
int exit_code() const;
|
||||
/* Show statistics of errors during command execution */
|
||||
int execution_errors() const;
|
||||
/* Quit the shell */
|
||||
void exit() const;
|
||||
private: /* Private executors */
|
||||
|
|
|
@ -401,7 +401,7 @@ void Shell<T>::print_commands() const {
|
|||
}
|
||||
|
||||
template <class T>
|
||||
void Shell<T>::exit() const {
|
||||
int Shell<T>::exit_code() const {
|
||||
/* Check all the command status, if we see fatal errors or minor errors, we drop an error code */
|
||||
int exit_code = 0;
|
||||
for (const int& status : command_status_) {
|
||||
|
@ -412,10 +412,14 @@ void Shell<T>::exit() const {
|
|||
}
|
||||
}
|
||||
|
||||
return exit_code;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
int Shell<T>::execution_errors() const {
|
||||
/* Show error message if we detect any errors */
|
||||
int num_err = 0;
|
||||
if (0 != exit_code) {
|
||||
VTR_LOG("\n");
|
||||
|
||||
for (const ShellCommandId& cmd : commands()) {
|
||||
if (command_status_[cmd] == CMD_EXEC_FATAL_ERROR) {
|
||||
VTR_LOG_ERROR("Command '%s' execution has fatal errors\n",
|
||||
|
@ -429,6 +433,20 @@ void Shell<T>::exit() const {
|
|||
num_err++;
|
||||
}
|
||||
}
|
||||
|
||||
return num_err;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
void Shell<T>::exit() const {
|
||||
/* Check all the command status, if we see fatal errors or minor errors, we drop an error code */
|
||||
int shell_exit_code = exit_code();
|
||||
|
||||
/* Show error message if we detect any errors */
|
||||
int num_err = 0;
|
||||
if (0 != shell_exit_code) {
|
||||
VTR_LOG("\n");
|
||||
num_err = execution_errors();
|
||||
}
|
||||
|
||||
VTR_LOG("\nFinish execution with %d errors\n",
|
||||
|
@ -440,7 +458,7 @@ void Shell<T>::exit() const {
|
|||
VTR_LOG("\nThank you for using %s!\n",
|
||||
name().c_str());
|
||||
|
||||
std::exit(exit_code);
|
||||
std::exit(shell_exit_code);
|
||||
}
|
||||
|
||||
/************************************************************************
|
||||
|
|
|
@ -99,18 +99,21 @@ int main(int argc, char** argv) {
|
|||
if (true == start_cmd_context.option_enable(start_cmd, opt_interactive)) {
|
||||
|
||||
shell.run_interactive_mode(openfpga_context);
|
||||
return 0;
|
||||
return shell.exit_code();
|
||||
}
|
||||
|
||||
if (true == start_cmd_context.option_enable(start_cmd, opt_script_mode)) {
|
||||
shell.run_script_mode(start_cmd_context.option_value(start_cmd, opt_script_mode).c_str(),
|
||||
openfpga_context,
|
||||
start_cmd_context.option_enable(start_cmd, opt_batch_exec));
|
||||
return 0;
|
||||
return shell.exit_code();
|
||||
}
|
||||
/* Reach here there is something wrong, show the help desk */
|
||||
openfpga::print_command_options(start_cmd);
|
||||
}
|
||||
|
||||
return 0;
|
||||
/* Reach here, it means shell execution has critical errors.
|
||||
* Return a code with fatal errors
|
||||
*/
|
||||
return 1;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue