From 3059b3a253dd491270a97cf492992fba70e9befe Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Sat, 11 Jun 2016 13:22:24 +0100 Subject: [PATCH] Extract ui type parsing to its own function --- src/main.cc | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/main.cc b/src/main.cc index 03da5bba..82444571 100644 --- a/src/main.cc +++ b/src/main.cc @@ -705,6 +705,15 @@ int run_pipe(StringView session) return 0; } +UIType parse_ui_type(StringView ui_name) +{ + if (ui_name == "ncurses") return UIType::NCurses; + if (ui_name == "json") return UIType::Json; + if (ui_name == "dummy") return UIType::Dummy; + + throw parameter_error(format("error: unknown ui type: '{}'", ui_name)); +} + int main(int argc, char* argv[]) { setlocale(LC_ALL, ""); @@ -776,17 +785,7 @@ int main(int argc, char* argv[]) } auto init_command = parser.get_switch("e").value_or(StringView{}); - auto ui_name = parser.get_switch("ui").value_or("ncurses"); - UIType ui_type; - if (ui_name == "ncurses") ui_type = UIType::NCurses; - else if (ui_name == "json") ui_type = UIType::Json; - else if (ui_name == "dummy") ui_type = UIType::Dummy; - else - { - write_stderr(format("error: unknown ui type: '{}'", ui_name)); - return -1; - } - + const UIType ui_type = parse_ui_type(parser.get_switch("ui").value_or("ncurses")); if (auto keys = parser.get_switch("f")) {