Skip to content

Commit

Permalink
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
arnemertz committed Aug 1, 2021
1 parent 77ebc63 commit d5ddcb4
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 1 deletion.
1 change: 0 additions & 1 deletion CMakeLists.txt
Expand Up @@ -50,7 +50,6 @@ add_subdirectory(src)

if (ENABLE_TESTING)
enable_testing()
message("Building Tests. Be sure to check out test/constexpr_tests for constexpr testing")
add_subdirectory(test)
endif ()

Expand Down
2 changes: 2 additions & 0 deletions src/CMakeLists.txt
Expand Up @@ -8,3 +8,5 @@ target_link_libraries(
project_warnings
CONAN_PKG::fmt
)

add_subdirectory(fix_cli)
8 changes: 8 additions & 0 deletions src/fix_cli/CMakeLists.txt
@@ -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}>)
25 changes: 25 additions & 0 deletions src/fix_cli/app.cpp
@@ -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
}
19 changes: 19 additions & 0 deletions src/fix_cli/app.hpp
@@ -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
2 changes: 2 additions & 0 deletions test/CMakeLists.txt
Expand Up @@ -9,3 +9,5 @@ add_library(catch_main STATIC catch_main.cpp)
target_link_libraries(catch_main PUBLIC CONAN_PKG::catch2)
target_link_libraries(catch_main PRIVATE project_options)

add_subdirectory(fix_cli)

6 changes: 6 additions & 0 deletions test/fix_cli/CMakeLists.txt
@@ -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)
34 changes: 34 additions & 0 deletions test/fix_cli/app_test.cpp
@@ -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);
}

0 comments on commit d5ddcb4

Please sign in to comment.