diff options
author | Egor Tensin <Egor.Tensin@gmail.com> | 2017-06-22 01:55:54 +0300 |
---|---|---|
committer | Egor Tensin <Egor.Tensin@gmail.com> | 2017-06-22 01:55:54 +0300 |
commit | 58abcc99fcd663435d32c71c90816c8a07081a47 (patch) | |
tree | b32ab9b60c01ac860a66369923c0953843f935d3 /utils/name2addr.cpp | |
parent | fix a CMake warning (diff) | |
download | winapi-debug-58abcc99fcd663435d32c71c90816c8a07081a47.tar.gz winapi-debug-58abcc99fcd663435d32c71c90816c8a07081a47.zip |
refactor command-line parameters parsing
Diffstat (limited to 'utils/name2addr.cpp')
-rw-r--r-- | utils/name2addr.cpp | 45 |
1 files changed, 13 insertions, 32 deletions
diff --git a/utils/name2addr.cpp b/utils/name2addr.cpp index f177c86..22c637b 100644 --- a/utils/name2addr.cpp +++ b/utils/name2addr.cpp @@ -23,47 +23,28 @@ namespace { public: explicit Name2Addr(const std::string& argv0) - : SettingsParser{argv0, build_options(), build_args()} - { } - - bool exit_with_usage() const { return help_flag; } - - const char* get_short_description() const override - { - return "[-h|--help] [--pdb ADDR,PATH]... [--] [NAME]..."; - } - - std::vector<PDB> pdbs; - std::vector<std::string> names; - - private: - Options build_options() + : SettingsParser{argv0} { - namespace program_options = boost::program_options; - Options descr{"options"}; - descr.add_options() - ("help,h", - program_options::bool_switch(&help_flag), - "show this message and exit") + visible.add_options() ("pdb", - program_options::value<std::vector<PDB>>(&pdbs) + boost::program_options::value<std::vector<PDB>>(&pdbs) ->value_name("ADDR,PATH"), - "load a PDB file") + "load a PDB file"); + hidden.add_options() ("name", - program_options::value<std::vector<std::string>>(&names) + boost::program_options::value<std::vector<std::string>>(&names) ->value_name("NAME"), "add a name to resolve"); - return descr; + positional.add("name", -1); } - static Arguments build_args() + const char* get_short_description() const override { - Arguments descr; - descr.add("name", -1); - return descr; + return "[-h|--help] [--pdb ADDR,PATH]... [--] [NAME]..."; } - bool help_flag = false; + std::vector<PDB> pdbs; + std::vector<std::string> names; }; void dump_error(const std::exception& e) @@ -90,7 +71,7 @@ int main(int argc, char* argv[]) { try { - const Name2Addr settings{argv[0]}; + Name2Addr settings{argv[0]}; try { @@ -102,7 +83,7 @@ int main(int argc, char* argv[]) return 1; } - if (settings.exit_with_usage()) + if (settings.exit_with_usage) { settings.usage(); return 0; |