refactor(command_line): Cleanup

This commit is contained in:
Michael Carlberg 2016-12-09 12:24:01 +01:00
parent 683ce7acc6
commit 5d5542169b
3 changed files with 15 additions and 12 deletions

View File

@ -37,9 +37,9 @@ namespace command_line {
class parser {
public:
using make_type = unique_ptr<parser>;
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;
};

View File

@ -10,10 +10,17 @@ POLYBAR_NS
/**
* Create instance
*/
cliparser::make_type cliparser::make(string scriptname, const clioptions& opts) {
return factory_util::unique<cliparser>("Usage: " + scriptname + " bar_name [OPTION...]", opts);
cliparser::make_type cliparser::make(string&& scriptname, const clioptions&& opts) {
return factory_util::unique<cliparser>(
"Usage: " + scriptname + " bar_name [OPTION...]", forward<decltype(opts)>(opts));
}
/**
* Construct parser
*/
cliparser::parser(string&& synopsis, const options&& opts)
: m_synopsis(forward<decltype(synopsis)>(synopsis)), m_opts(forward<decltype(opts)>(opts)) {}
/**
* Print application usage message
*/

View File

@ -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<string> 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<string>(conf.bar_section(), cli->get("dump")) << endl;
std::cout << conf.get<string>(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{};
}