diff --git a/tools/elf2rpl/CMakeLists.txt b/tools/elf2rpl/CMakeLists.txt index f435a3a..b705a6c 100644 --- a/tools/elf2rpl/CMakeLists.txt +++ b/tools/elf2rpl/CMakeLists.txt @@ -7,6 +7,7 @@ add_executable(elf2rpl ${SOURCE_FILES} ${HEADER_FILES}) target_link_libraries(elf2rpl + excmd fmt zlib) diff --git a/tools/elf2rpl/main.cpp b/tools/elf2rpl/main.cpp index 013c3cb..8cc9584 100644 --- a/tools/elf2rpl/main.cpp +++ b/tools/elf2rpl/main.cpp @@ -2,6 +2,7 @@ #include "utils.h" #include +#include #include #include #include @@ -919,15 +920,46 @@ writeRpl(ElfFile &file, const std::string &filename) return true; } -int main(int argc, const char **argv) +int main(int argc, char **argv) { - if (argc < 3) { - fmt::print("Usage: {} ", argv[0]); + excmd::parser parser; + excmd::option_state options; + using excmd::description; + using excmd::value; + + try { + parser.global_options() + .add_option("H,help", + description { "Show help." }) + .add_option("r,rpl", + description { "Generate an RPL instead of an RPX" }); + + parser.default_command() + .add_argument("src", + description { "Path to input elf file" }, + value {}) + .add_argument("dst", + description { "Path to output rpl file" }, + value {}); + + options = parser.parse(argc, argv); + } catch (excmd::exception ex) { + fmt::print("Error parsing options: {}\n", ex.what()); return -1; } - auto src = std::string { argv[1] }; - auto dst = std::string { argv[2] }; + if (options.empty() + || options.has("help") + || !options.has("src") + || !options.has("dst")) { + fmt::print("{} src dst\n", argv[0]); + fmt::print("{}\n", parser.format_help(argv[0])); + return 0; + } + + auto src = options.get("src"); + auto dst = options.get("dst"); + auto isRpl = options.has("rpl"); // Read elf into memory object! ElfFile elf;