Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
add cli application class
fix::cli::app processes the command line arguments and outputs results on the console. First unit test checks for usage output on erroneous arguments
- Loading branch information
Showing
8 changed files
with
96 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,5 @@ target_link_libraries( | |
project_warnings | ||
CONAN_PKG::fmt | ||
) | ||
|
||
add_subdirectory(fix_cli) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
set(FIX_CLI_SOURCES | ||
app.cpp | ||
) | ||
|
||
|
||
add_library(fix_cli ${FIX_CLI_SOURCES}) | ||
target_link_libraries(fix_cli PRIVATE project_warnings project_options) | ||
target_include_directories(fix_cli PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#include "app.hpp" | ||
|
||
#include <ostream> | ||
|
||
using namespace fix::cli; | ||
using namespace std::string_view_literals; | ||
|
||
namespace { | ||
constexpr auto USAGE = R"(usage: fix [--help] <command> [<args>] | ||
Available commands: | ||
create Create a new issue | ||
setstatus Set the status of an issue | ||
list List all existing issues | ||
show Show a specific issue | ||
)"sv; | ||
} | ||
|
||
app::app(std::ostream &out) | ||
{ | ||
out << USAGE; | ||
} | ||
|
||
void app::run(const std::vector<std::string_view>& /*args*/) { //NOLINT | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#ifndef FIX_APP_HPP | ||
#define FIX_APP_HPP | ||
|
||
#include <iosfwd> | ||
#include <string_view> | ||
#include <vector> | ||
|
||
namespace fix::cli { | ||
|
||
class app { | ||
public: | ||
explicit app(std::ostream &out); | ||
|
||
void run(std::vector<std::string_view> const &); | ||
}; | ||
|
||
} | ||
|
||
#endif //FIX_APP_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
set(FIX_CLI_TEST_SOURCES | ||
app_test.cpp | ||
) | ||
|
||
add_executable(fix_cli_tests ${FIX_CLI_TEST_SOURCES}) | ||
target_link_libraries(fix_cli_tests PRIVATE project_warnings project_options catch_main fix_cli) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#include <catch2/catch.hpp> | ||
|
||
#include <sstream> | ||
#include <string_view> | ||
|
||
#include "app.hpp" | ||
|
||
using namespace std::literals; | ||
|
||
namespace { | ||
constexpr auto USAGE = R"(usage: fix [--help] <command> [<args>] | ||
Available commands: | ||
create Create a new issue | ||
setstatus Set the status of an issue | ||
list List all existing issues | ||
show Show a specific issue | ||
)"sv; | ||
} | ||
|
||
TEST_CASE("Prints usage and commands...") { | ||
std::stringstream out; | ||
fix::cli::app app{out}; | ||
|
||
SECTION("... when run without commands") { | ||
app.run({}); | ||
}SECTION("... when run with --help option") { | ||
app.run({"--help"}); | ||
}SECTION("... when run with -h option") { | ||
app.run({"-h"}); | ||
} | ||
|
||
CHECK(out.str() == USAGE); | ||
} |