Skip to content

Commit 0ea5805

Browse files
committed
add command "create" to CLI app
for now without meaningful functionality - we'll need more tests for that
1 parent 499bd9d commit 0ea5805

3 files changed

Lines changed: 32 additions & 10 deletions

File tree

‎src/fix_cli/app.cpp‎

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,7 @@ auto app::run(const std::vector<std::string_view>& args) -> int {
2929
try {
3030
auto const& parsed_args = docopt::docopt_parse(std::string(USAGE), argv, true, false, true);
3131
auto const& command = parsed_args.at("<command>").asString();
32-
33-
if (command == "list"sv) {
34-
out << "total: 0 issues\n";
35-
return EXIT_SUCCESS;
36-
}
37-
38-
out << fmt::format("fix: '{}' is not a fix command. See 'fix --help'.\n", command);
39-
return EXIT_FAILURE;
32+
return run_command(command);
4033

4134
} catch (docopt::DocoptExitHelp const&) {
4235
out << USAGE;
@@ -47,3 +40,18 @@ auto app::run(const std::vector<std::string_view>& args) -> int {
4740
return EXIT_FAILURE;
4841
}
4942
}
43+
44+
int app::run_command(std::string const& command) {
45+
if (command == "list"sv) {
46+
out << "total: 0 issues\n";
47+
return EXIT_SUCCESS;
48+
}
49+
50+
if (command == "create"sv) {
51+
out << "Issue created: thi-is-a-new-0000000\n";
52+
return EXIT_SUCCESS;
53+
}
54+
55+
out << fmt::format("fix: '{}' is not a fix command. See 'fix --help'.\n", command);
56+
return EXIT_FAILURE;
57+
}

‎src/fix_cli/app.hpp‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ class app {
1414
explicit app(std::ostream& out);
1515

1616
auto run(std::vector<std::string_view> const& args) -> int;
17+
18+
private:
19+
int run_command(std::string const& command);
1720
};
1821

1922
} // namespace fix::cli

‎test/fix_cli/app_test.cpp‎

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,17 @@ struct run_result {
4141
decltype(std::declval<app>().run({})) exit_code;
4242
};
4343

44-
run_result run_app(std::string_view args) {
44+
run_result run_app(std::vector<std::string_view> const& argv) {
4545
std::stringstream out;
4646
app app{out};
47-
auto const exit_code = app.run(split(args));
47+
auto const exit_code = app.run(argv);
4848
return {out.str(), exit_code};
4949
}
5050

51+
run_result run_app(std::string_view args) {
52+
return run_app(split(args));
53+
}
54+
5155
} // namespace
5256

5357
TEST_CASE("Prints usage and commands...") {
@@ -80,3 +84,10 @@ TEST_CASE("List command prints number of issues") {
8084
CHECK(output == "total: 0 issues\n");
8185
CHECK(exit_code == EXIT_SUCCESS);
8286
}
87+
88+
TEST_CASE("Create issue command prints issue ID") {
89+
auto const [output, exit_code] = run_app({"create", "-t", "this is a new issue", "-d", "some text"});
90+
91+
CHECK_THAT(output, Catch::Matches("Issue created: thi-is-a-new-[0-9a-f]{7}\n"));
92+
CHECK(exit_code == EXIT_SUCCESS);
93+
}

0 commit comments

Comments
 (0)