Skip to content

Commit 3a72ef9

Browse files
committed
Factor out methods for commands in CLI app
The run_app method has become too large and does too much. The detail implementation of the individual commands needs separate functions.
1 parent 81ce342 commit 3a72ef9

File tree

2 files changed

+22
-12
lines changed

2 files changed

+22
-12
lines changed

src/fix_cli/app.cpp

+20-12
Original file line numberDiff line numberDiff line change
@@ -52,23 +52,31 @@ auto app::run(const std::vector<std::string_view>& args) -> int {
5252

5353
int app::run_command(std::string const& command, const std::vector<std::string>& argv) {
5454
if (command == "list"sv) {
55-
domain::application_service application_service;
56-
auto const count = application_service.list();
57-
out << fmt::format("total: {} issues\n", count);
58-
return EXIT_SUCCESS;
55+
return list();
5956
}
6057

6158
if (command == "create"sv) {
62-
auto const& parsed_args = docopt::docopt_parse(std::string(CREATE_USAGE), argv, false, false, false);
63-
auto const& title = parsed_args.at("--title").asString();
64-
auto const& description = parsed_args.at("--descr").asString();
65-
66-
domain::application_service application_service;
67-
const auto issue_id = application_service.create(title, description);
68-
out << fmt::format("Issue created: {}\n", issue_id);
69-
return EXIT_SUCCESS;
59+
return create(argv);
7060
}
7161

7262
out << fmt::format("fix: '{}' is not a fix command. See 'fix --help'.\n", command);
7363
return EXIT_FAILURE;
7464
}
65+
66+
int app::list() {
67+
domain::application_service application_service;
68+
auto const count = application_service.list();
69+
out << fmt::format("total: {} issues\n", count);
70+
return EXIT_SUCCESS;
71+
}
72+
73+
int app::create(std::vector<std::string> const& argv) {
74+
auto const& parsed_args = docopt::docopt_parse(std::string(CREATE_USAGE), argv, false, false, false);
75+
auto const& title = parsed_args.at("--title").asString();
76+
auto const& description = parsed_args.at("--descr").asString();
77+
78+
domain::application_service application_service;
79+
const auto issue_id = application_service.create(title, description);
80+
this->out << fmt::format("Issue created: {}\n", issue_id);
81+
return EXIT_SUCCESS;
82+
}

src/fix_cli/app.hpp

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ class app {
1717

1818
private:
1919
int run_command(std::string const& command, const std::vector<std::string>& argv);
20+
int list();
21+
int create(std::vector<std::string> const& argv);
2022
};
2123

2224
} // namespace fix::cli

0 commit comments

Comments
 (0)