From 5d5542169b815c912813c74009645d13a95e8fd0 Mon Sep 17 00:00:00 2001 From: Michael Carlberg Date: Fri, 9 Dec 2016 12:24:01 +0100 Subject: [PATCH] refactor(command_line): Cleanup --- include/components/command_line.hpp | 6 +++--- src/components/command_line.cpp | 11 +++++++++-- src/main.cpp | 10 +++------- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/include/components/command_line.hpp b/include/components/command_line.hpp index c2e203e6..72277cf4 100644 --- a/include/components/command_line.hpp +++ b/include/components/command_line.hpp @@ -37,9 +37,9 @@ namespace command_line { class parser { public: using make_type = unique_ptr; - static make_type make(string scriptname, const options& opts); + static make_type make(string&& scriptname, const options&& opts); - explicit parser(const string& synopsis, const options& opts) : m_synopsis(synopsis), m_opts(opts) {} + explicit parser(string&& synopsis, const options&& opts); void usage() const; @@ -59,7 +59,7 @@ namespace command_line { private: string m_synopsis; - options m_opts; + const options m_opts; values m_optvalues; bool m_skipnext = false; }; diff --git a/src/components/command_line.cpp b/src/components/command_line.cpp index b8ccb55b..7d404a9e 100644 --- a/src/components/command_line.cpp +++ b/src/components/command_line.cpp @@ -10,10 +10,17 @@ POLYBAR_NS /** * Create instance */ -cliparser::make_type cliparser::make(string scriptname, const clioptions& opts) { - return factory_util::unique("Usage: " + scriptname + " bar_name [OPTION...]", opts); +cliparser::make_type cliparser::make(string&& scriptname, const clioptions&& opts) { + return factory_util::unique( + "Usage: " + scriptname + " bar_name [OPTION...]", forward(opts)); } +/** + * Construct parser + */ +cliparser::parser(string&& synopsis, const options&& opts) + : m_synopsis(forward(synopsis)), m_opts(forward(opts)) {} + /** * Print application usage message */ diff --git a/src/main.cpp b/src/main.cpp index 77d7d0e8..0a37cb62 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -13,9 +13,6 @@ using namespace polybar; -using std::cout; -using std::endl; - struct exit_success {}; struct exit_failure {}; @@ -70,8 +67,7 @@ int main(int argc, char** argv) { string scriptname{argv[0]}; vector args{argv + 1, argv + argc}; - cliparser::make_type cli{cliparser::make(move(scriptname), opts)}; - + cliparser::make_type cli{cliparser::make(move(scriptname), move(opts))}; cli->process_input(args); if (cli->has("quiet")) { @@ -112,7 +108,7 @@ int main(int argc, char** argv) { // Dump requested data //================================================== if (cli->has("dump")) { - cout << conf.get(conf.bar_section(), cli->get("dump")) << endl; + std::cout << conf.get(conf.bar_section(), cli->get("dump")) << std::endl; throw exit_success{}; } @@ -133,7 +129,7 @@ int main(int argc, char** argv) { ctrl = controller::make(move(path_confwatch), enable_ipc, cli->has("stdout")); if (cli->has("print-wmname")) { - cout << ctrl->opts().wmname << endl; + std::cout << ctrl->opts().wmname << std::endl; throw exit_success{}; }