Skip to content

Commit 4724eac

Browse files
committed
Parse create command options
The title and description passed to the create command have to be forwarded to the application service. This is achieved using docopt again. Error handling is currently not done at that level as there are no tests requiring it.
1 parent aaa7c0b commit 4724eac

File tree

5 files changed

+23
-9
lines changed

5 files changed

+23
-9
lines changed

behave/issue_list_create.feature

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ Feature: Creating and listing issues
66
Then it prints "total: 0 issues"
77
And terminates with exit code OK
88

9-
@wip
109
Scenario: create an issue
1110
Given an empty issue repository
1211
When we create an issue titled "My first issue in Fix" with description

behave/steps/fix_cli.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def _start_fix_with_args(context, args):
1212

1313
@when(u'we call Fix with argument list "{args}"')
1414
def start_fix(context, args):
15-
_start_fix_with_args(context, shlex.split(args.strip(), posix=False))
15+
_start_fix_with_args(context, shlex.split(args.strip(), posix=True))
1616

1717

1818
@when(u'we call Fix without arguments')

src/fix_cli/app.cpp

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,14 @@ Available commands:
2121
list List all existing issues
2222
show Show a specific issue
2323
)"sv;
24-
}
24+
25+
constexpr auto CREATE_USAGE = R"(usage: fix create -t <title> -d <descr>
26+
27+
Options:
28+
-t <title> --title=<title> Title of the new issue
29+
-d <descr> --descr=<descr> Description text
30+
)";
31+
} // namespace
2532

2633
app::app(std::ostream& out) : out{out} {}
2734

@@ -31,7 +38,7 @@ auto app::run(const std::vector<std::string_view>& args) -> int {
3138
try {
3239
auto const& parsed_args = docopt::docopt_parse(std::string(USAGE), argv, true, false, true);
3340
auto const& command = parsed_args.at("<command>").asString();
34-
return run_command(command);
41+
return run_command(command, argv);
3542

3643
} catch (docopt::DocoptExitHelp const&) {
3744
out << USAGE;
@@ -43,15 +50,19 @@ auto app::run(const std::vector<std::string_view>& args) -> int {
4350
}
4451
}
4552

46-
int app::run_command(std::string const& command) {
53+
int app::run_command(std::string const& command, const std::vector<std::string>& argv) {
4754
if (command == "list"sv) {
4855
out << "total: 0 issues\n";
4956
return EXIT_SUCCESS;
5057
}
5158

5259
if (command == "create"sv) {
60+
auto const& parsed_args = docopt::docopt_parse(std::string(CREATE_USAGE), argv, false, false, false);
61+
auto const& title = parsed_args.at("--title").asString();
62+
auto const& description = parsed_args.at("--descr").asString();
63+
5364
domain::application_service application_service;
54-
const auto issue_id = application_service.create("this is a new issue", "");
65+
const auto issue_id = application_service.create(title, description);
5566
out << fmt::format("Issue created: {}\n", issue_id);
5667
return EXIT_SUCCESS;
5768
}

src/fix_cli/app.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class app {
1616
auto run(std::vector<std::string_view> const& args) -> int;
1717

1818
private:
19-
int run_command(std::string const& command);
19+
int run_command(std::string const& command, const std::vector<std::string>& argv);
2020
};
2121

2222
} // namespace fix::cli

test/fix_cli/app_test.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,12 @@ TEST_CASE("List command prints number of issues") {
8686
}
8787

8888
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"});
89+
auto const& [title, description, id_prefix]
90+
= GENERATE(std::tuple("this is a new issue", "some text", "thi-is-a-new"),
91+
std::tuple("My first issue in Fix", "Dorem Fixum dolor sit amet", "my-fir-iss-in"));
9092

91-
CHECK_THAT(output, Catch::Matches("Issue created: thi-is-a-new-[0-9a-f]{7}\n"));
93+
auto const [output, exit_code] = run_app({"create", "-t", title, "-d", description});
94+
95+
CHECK_THAT(output, Catch::Matches(fmt::format("Issue created: {}-[0-9a-f]{{7}}\n", id_prefix)));
9296
CHECK(exit_code == EXIT_SUCCESS);
9397
}

0 commit comments

Comments
 (0)