diff --git a/binaries/opae.io/main.cpp b/binaries/opae.io/main.cpp index b08a499770ac..c6ef3e30077e 100644 --- a/binaries/opae.io/main.cpp +++ b/binaries/opae.io/main.cpp @@ -45,9 +45,9 @@ struct vfio_device *the_device = nullptr; struct mmio_region *the_region = nullptr; const char *program = "opae.io"; -const int major = 0; -const int minor = 2; -const int patch = 7; +const int major = 1; +const int minor = 0; +const int patch = 0; py::tuple version() { @@ -196,8 +196,6 @@ class opae_io_cli { struct mmio_region *region_; }; -void command_line_help(void); - PYBIND11_EMBEDDED_MODULE(opae_io, m) { m.def("read_csr", &read_csr); m.def("peek", &peek); @@ -419,15 +417,23 @@ int main(int argc, char *argv[]) auto pysys = py::module::import("sys"); auto pyargs = args_to_list(argc, argv); pysys.attr("argv") = pyargs; + + py::module main_mod = py::module::import("__main__"); + main_mod.attr("_MODULE_SOURCE_CODE") = pymain; + try { py::exec(pymain, globals); } catch(py::error_already_set &pyerr) { - //std::cerr << pyerr.what() << std::endl; if (pyerr.matches(PyExc_SystemExit)) { - std::cerr << "Command line parse failed." << std::endl; - return 1; - } else if (pyerr.matches(PyExc_TypeError)) { - std::cerr << "No suitable accelerator device found." << std::endl; + int rc = cli->return_code(); + if ((rc == 99) || (rc == 100)) { // help or version requested + return rc; // -or- argparse failed. + } else if (rc != 0) { + std::cerr << pyerr.what() << std::endl; + return rc; + } + } else { + std::cerr << pyerr.what() << std::endl; return 2; } } @@ -435,9 +441,6 @@ int main(int argc, char *argv[]) return cli->return_code(); } - //builtins.attr("the_device") = the_device; - //builtins.attr("the_region") = the_region; - char *history = readline_init(); while (true) { @@ -562,56 +565,3 @@ void readline_destroy(char *history) free(history); } } - -void command_line_help(void) -{ - std::cout << "opae.io - peek and poke FPGA CSRs" << std::endl - << std::endl - << "\topae.io" << std::endl - << "\topae.io -v | --version" << std::endl - << "\topae.io -h | --help" << std::endl - << "\topae.io ls" << std::endl - << "\topae.io init [:]" << std::endl - << "\topae.io release " << std::endl - << "\topae.io " << std::endl - << "\topae.io " << std::endl - << "\topae.io peek " << std::endl - << "\topae.io poke " << std::endl - << "\topae.io