diff --git a/Source/Tools/pidof/CMakeLists.txt b/Source/Tools/pidof/CMakeLists.txt index 8a5f794268..cde47cd9ee 100644 --- a/Source/Tools/pidof/CMakeLists.txt +++ b/Source/Tools/pidof/CMakeLists.txt @@ -1,11 +1,7 @@ add_executable(FEXpidof pidof.cpp) -target_include_directories(FEXpidof - PRIVATE - ${PROJECT_SOURCE_DIR}/Source/Common/cpp-optparse/) - target_link_libraries(FEXpidof PRIVATE - cpp-optparse + Common fmt::fmt ) diff --git a/Source/Tools/pidof/pidof.cpp b/Source/Tools/pidof/pidof.cpp index 877f8d2610..eb2fbafaa5 100644 --- a/Source/Tools/pidof/pidof.cpp +++ b/Source/Tools/pidof/pidof.cpp @@ -1,5 +1,6 @@ // SPDX-License-Identifier: MIT -#include "OptionParser.h" +#include +#include "Common/MicroArgParser.h" #include #include @@ -14,35 +15,34 @@ namespace Config { bool SingleShot {}; bool SkipZombie {true}; bool DoNotDisplay {}; -std::string Separator {" "}; +std::string_view Separator {" "}; std::unordered_set OmitPids; std::unordered_set Programs; void LoadOptions(int argc, char** argv) { - optparse::OptionParser Parser {}; - - Parser.add_option("-s").help("Single shot - Only returns one pid").action("store_true").set_default(SingleShot); - - Parser.add_option("-q") - .help("Do not display matched PIDs to stdout. Simply exit with status of true or false if a PID was found") - .action("store_true") - .set_default(DoNotDisplay); - - Parser.add_option("-z").help("Try to detect zombie processes - Usually zombie processes are skipped").action("store_false").set_default(SkipZombie); - - Parser.add_option("-d").help("Use a different separator if more than one pid is show - Default is space").set_default(Separator); - - Parser.add_option("-o").help("Ignore processes with matched pids").action("append"); - - optparse::Values Options = Parser.parse_args(argc, argv); - - SingleShot = Options.get("s"); - DoNotDisplay = Options.get("q"); - SkipZombie = Options.get("z"); - Separator = Options["d"]; - - for (const auto& Omit : Options.all("o")) { - std::istringstream ss {Omit}; + static std::array Args = {{ + {FEX::MicroArgParser::ParseMember::Type::Bool, "-s", {}, "Single shot - Only returns one pid", "0"}, + {FEX::MicroArgParser::ParseMember::Type::Bool, "-q", {}, "Do not display matched PIDs to stdout. Simply exit with status of true or false if a PID was found", "0"}, + {FEX::MicroArgParser::ParseMember::Type::BoolInvert, "-z", {}, "Try to detect zombie processes - Usually zombie processes are skipped", "1"}, + {FEX::MicroArgParser::ParseMember::Type::String, "-d", {}, "Use a different separator if more than one pid is show - Default is space", " "}, + {FEX::MicroArgParser::ParseMember::Type::StringArray, "-o", {}, "Ignore processes with matched pids", {}}, + + // Defaults + {FEX::MicroArgParser::ParseMember::Type::Bool, "-v", "--version", "show program's verison number and exit", "0"}, + {FEX::MicroArgParser::ParseMember::Type::Bool, "-h", "--help", "show this help message and exit", "0"}, + }}; + + // Load the arguments + FEX::MicroArgParser Parser(Args); + Parser.Parse(argc, argv); + + SingleShot = Parser.Get("-s"); + DoNotDisplay = Parser.Get("-q"); + SkipZombie = Parser.Get("-z"); + Separator = Parser.Get("-d"); + + for (const auto& Omit : Parser.GetVector("-o")) { + std::istringstream ss {fextl::string(Omit)}; std::string sub; while (std::getline(ss, sub, ',')) { int64_t pid; @@ -57,8 +57,8 @@ void LoadOptions(int argc, char** argv) { } } - for (const auto& Program : Parser.args()) { - Programs.emplace(Program); + for (size_t i = Parser.GetRemainingArgumentsIndex(); i < argc; ++i) { + Programs.emplace(argv[i]); } } } // namespace Config