mirror of
https://github.com/CLIUtils/CLI11.git
synced 2025-04-29 12:13:52 +00:00
Adding warnings and fixes, CLI11 target, support for VIM Syntastic
This commit is contained in:
parent
80e2c70b63
commit
ee9219e0f8
@ -1,3 +1,8 @@
|
||||
## Version 0.9 (in progress)
|
||||
|
||||
* Better CMake named target (CLI11)
|
||||
* More warnings added, fixed
|
||||
|
||||
## Version 0.8
|
||||
|
||||
* Moved to CLIUtils on GitHub
|
||||
|
@ -9,18 +9,18 @@ if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
|
||||
set(CMAKE_CXX_STANDARD 11)
|
||||
set(CMAKE_CXX_EXTENSIONS OFF)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
# Be moderately paranoid with flags
|
||||
if(CMAKE_CXX_COMPILER_ID EQUAL "MSVC")
|
||||
add_definitions("/W4")
|
||||
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
|
||||
else()
|
||||
add_definitions("-Wall -Wextra -pedantic")
|
||||
endif()
|
||||
else()
|
||||
set(CUR_PROJ OFF)
|
||||
endif()
|
||||
|
||||
# Be moderately paranoid with flags
|
||||
if(CMAKE_COMPILER_IS_GNUCC)
|
||||
add_definitions("-Wall -Wextra -pedantic")
|
||||
endif()
|
||||
if(MSVC)
|
||||
add_definitions("/W4")
|
||||
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
|
||||
endif()
|
||||
|
||||
|
||||
if(CMAKE_BUILD_TYPE STREQUAL Coverage)
|
||||
@ -28,11 +28,10 @@ if(CMAKE_BUILD_TYPE STREQUAL Coverage)
|
||||
setup_target_for_coverage(CLI_coverage ctest coverage)
|
||||
endif()
|
||||
|
||||
add_library(CLI INTERFACE)
|
||||
target_include_directories(CLI INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/include")
|
||||
|
||||
file(GLOB CLI_headers "${CMAKE_CURRENT_SOURCE_DIR}/include/CLI/*")
|
||||
# To see in IDE, must be listed for target
|
||||
add_library(CLI11 INTERFACE)
|
||||
target_include_directories(CLI11 INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/include")
|
||||
|
||||
# Single file test
|
||||
option(CLI_SINGLE_FILE "Generate a single header file (and test)" ${CUR_PROJ})
|
||||
@ -45,11 +44,11 @@ if(CLI_SINGLE_FILE)
|
||||
add_custom_target(generate_cli_single_file ALL
|
||||
DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/include/CLI11.hpp")
|
||||
|
||||
add_library(CLI_SINGLE INTERFACE)
|
||||
target_link_libraries(CLI_SINGLE INTERFACE CLI)
|
||||
add_dependencies(CLI_SINGLE generate_cli_single_file)
|
||||
target_compile_definitions(CLI_SINGLE INTERFACE -DCLI_SINGLE_FILE)
|
||||
target_include_directories(CLI_SINGLE INTERFACE "${CMAKE_CURRENT_BINARY_DIR}/include/")
|
||||
add_library(CLI11_SINGLE INTERFACE)
|
||||
target_link_libraries(CLI11_SINGLE INTERFACE CLI11)
|
||||
add_dependencies(CLI11_SINGLE generate_cli_single_file)
|
||||
target_compile_definitions(CLI11_SINGLE INTERFACE -DCLI_SINGLE_FILE)
|
||||
target_include_directories(CLI11_SINGLE INTERFACE "${CMAKE_CURRENT_BINARY_DIR}/include/")
|
||||
endif()
|
||||
|
||||
option(CLI_SINGLE_FILE_TESTS "Duplicate all the tests for a single file build" OFF)
|
||||
|
@ -62,7 +62,7 @@ As you probably have guessed, the list of features above are all covered by this
|
||||
To use, there are two methods:
|
||||
|
||||
1. Copy `CLI11.hpp` from the [most recent release][Github-releases] into your include directory, and you are set. This is combined from the source files for every release. This includes the entire command parser library, but does not include separate utilities (like `Timer`, `AutoTimer`). The utilities are completely self contained and can be copied separately.
|
||||
2. Checkout the repository and add as a subdirectory for CMake. You can use the `cli` interface target when linking. (CMake 3.4+ recommended) Or, use the `AddCLI.cmake` supplied in [CLIUtils cmake helpers][cltools-cmake].
|
||||
2. Checkout the repository and add as a subdirectory for CMake. You can use the `CLI11` interface target when linking. (CMake 3.4+ recommended) Or, instead of explicitly downloading the library, use the `AddCLI.cmake` supplied in [CLIUtils cmake helpers][cltools-cmake].
|
||||
|
||||
To build the tests, checkout the repository and use CMake:
|
||||
|
||||
|
@ -1,8 +1,8 @@
|
||||
add_executable(try try.cpp ${CLI_headers})
|
||||
target_link_libraries(try PUBLIC CLI)
|
||||
target_link_libraries(try PUBLIC CLI11)
|
||||
|
||||
add_executable(try1 try1.cpp ${CLI_headers})
|
||||
target_link_libraries(try1 PUBLIC CLI)
|
||||
target_link_libraries(try1 PUBLIC CLI11)
|
||||
|
||||
add_executable(try2 try2.cpp ${CLI_headers})
|
||||
target_link_libraries(try2 PUBLIC CLI)
|
||||
target_link_libraries(try2 PUBLIC CLI11)
|
||||
|
@ -27,7 +27,7 @@ namespace CLI {
|
||||
|
||||
namespace detail {
|
||||
enum class Classifer {NONE, POSITIONAL_MARK, SHORT, LONG, SUBCOMMAND};
|
||||
class AppFriend;
|
||||
struct AppFriend;
|
||||
}
|
||||
|
||||
class App;
|
||||
|
@ -113,7 +113,7 @@ protected:
|
||||
|
||||
/// Making an option by hand is not defined, it must be made by the App class
|
||||
Option(std::string name, std::string description = "", std::function<bool(results_t)> callback=[](results_t){return true;}, bool default_=true, App* parent = nullptr) :
|
||||
description_(description), callback_(callback), default_(default_), parent_(parent) {
|
||||
description_(description), default_(default_), parent_(parent), callback_(callback) {
|
||||
std::tie(snames_, lnames_, pname_) = detail::get_names(detail::split_names(name));
|
||||
}
|
||||
|
||||
|
@ -24,12 +24,12 @@ protected:
|
||||
/// This is the title of the timer
|
||||
std::string title_;
|
||||
|
||||
/// This is the starting point (when the timer was created)
|
||||
time_point start_;
|
||||
|
||||
/// This is the function that is used to format most of the timing message
|
||||
time_print_t time_print_;
|
||||
|
||||
/// This is the starting point (when the timer was created)
|
||||
time_point start_;
|
||||
|
||||
public:
|
||||
|
||||
/// Standard print function, this one is set by default
|
||||
|
2
tests/.syntastic_cpp_config
Normal file
2
tests/.syntastic_cpp_config
Normal file
@ -0,0 +1,2 @@
|
||||
-I../build/googletest-src/googletest/include/
|
||||
-I../build/googletest-src/googlemock/include/
|
@ -21,12 +21,12 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR})
|
||||
foreach(T ${CLI_TESTS})
|
||||
|
||||
add_executable(${T} ${T}.cpp ${CLI_headers})
|
||||
target_link_libraries(${T} PUBLIC CLI)
|
||||
target_link_libraries(${T} PUBLIC CLI11)
|
||||
add_gtest(${T})
|
||||
|
||||
if(CLI_SINGLE_FILE AND CLI_SINGLE_FILE_TESTS)
|
||||
add_executable(${T}_Single ${T}.cpp)
|
||||
target_link_libraries(${T}_Single PUBLIC CLI_SINGLE)
|
||||
target_link_libraries(${T}_Single PUBLIC CLI11_SINGLE)
|
||||
add_gtest(${T}_Single)
|
||||
endif()
|
||||
|
||||
@ -35,7 +35,7 @@ endforeach()
|
||||
foreach(T ${CLI_SINGLE_TESTS})
|
||||
|
||||
add_executable(${T} ${T}.cpp ${CLI_headers})
|
||||
target_link_libraries(${T} PUBLIC CLI)
|
||||
target_link_libraries(${T} PUBLIC CLI11)
|
||||
add_gtest(${T})
|
||||
|
||||
endforeach()
|
||||
|
@ -159,7 +159,7 @@ TEST_F(TApp, IncorrectConstructionDuplicateRequires) {
|
||||
|
||||
TEST_F(TApp, IncorrectConstructionDuplicateRequiresTxt) {
|
||||
auto cat = app.add_flag("--cat");
|
||||
auto other = app.add_flag("--other");
|
||||
app.add_flag("--other");
|
||||
ASSERT_NO_THROW(cat->requires("--other"));
|
||||
EXPECT_THROW(cat->requires("--other"),CLI::OptionAlreadyAdded);
|
||||
}
|
||||
@ -173,7 +173,7 @@ TEST_F(TApp, IncorrectConstructionDuplicateExcludes) {
|
||||
|
||||
TEST_F(TApp, IncorrectConstructionDuplicateExcludesTxt) {
|
||||
auto cat = app.add_flag("--cat");
|
||||
auto other = app.add_flag("--other");
|
||||
app.add_flag("--other");
|
||||
ASSERT_NO_THROW(cat->excludes("--other"));
|
||||
EXPECT_THROW(cat->excludes("--other"),CLI::OptionAlreadyAdded);
|
||||
}
|
||||
|
@ -7,7 +7,7 @@
|
||||
|
||||
TEST(Split, SimpleByToken) {
|
||||
auto out = CLI::detail::split("one.two.three", '.');
|
||||
ASSERT_EQ(3, out.size());
|
||||
ASSERT_EQ((size_t) 3, out.size());
|
||||
EXPECT_EQ("one", out.at(0));
|
||||
EXPECT_EQ("two", out.at(1));
|
||||
EXPECT_EQ("three", out.at(2));
|
||||
@ -15,13 +15,13 @@ TEST(Split, SimpleByToken) {
|
||||
|
||||
TEST(Split, Single) {
|
||||
auto out = CLI::detail::split("one", '.');
|
||||
ASSERT_EQ(1, out.size());
|
||||
ASSERT_EQ((size_t) 1, out.size());
|
||||
EXPECT_EQ("one", out.at(0));
|
||||
}
|
||||
|
||||
TEST(Split, Empty) {
|
||||
auto out = CLI::detail::split("", '.');
|
||||
ASSERT_EQ(1, out.size());
|
||||
ASSERT_EQ((size_t) 1, out.size());
|
||||
EXPECT_EQ("", out.at(0));
|
||||
}
|
||||
|
||||
|
@ -17,12 +17,12 @@ TEST(StringBased, First) {
|
||||
|
||||
std::vector<CLI::detail::ini_ret_t> output = CLI::detail::parse_ini(ofile);
|
||||
|
||||
EXPECT_EQ(2, output.size());
|
||||
EXPECT_EQ((size_t) 2, output.size());
|
||||
EXPECT_EQ("one", output.at(0).name());
|
||||
EXPECT_EQ(1, output.at(0).inputs.size());
|
||||
EXPECT_EQ((size_t) 1, output.at(0).inputs.size());
|
||||
EXPECT_EQ("three", output.at(0).inputs.at(0));
|
||||
EXPECT_EQ("two", output.at(1).name());
|
||||
EXPECT_EQ(1, output.at(1).inputs.size());
|
||||
EXPECT_EQ((size_t) 1, output.at(1).inputs.size());
|
||||
EXPECT_EQ("four", output.at(1).inputs.at(0));
|
||||
|
||||
}
|
||||
@ -39,12 +39,12 @@ TEST(StringBased, FirstWithComments) {
|
||||
|
||||
auto output = CLI::detail::parse_ini(ofile);
|
||||
|
||||
EXPECT_EQ(2, output.size());
|
||||
EXPECT_EQ((size_t) 2, output.size());
|
||||
EXPECT_EQ("one", output.at(0).name());
|
||||
EXPECT_EQ(1, output.at(0).inputs.size());
|
||||
EXPECT_EQ((size_t) 1, output.at(0).inputs.size());
|
||||
EXPECT_EQ("three", output.at(0).inputs.at(0));
|
||||
EXPECT_EQ("two", output.at(1).name());
|
||||
EXPECT_EQ(1, output.at(1).inputs.size());
|
||||
EXPECT_EQ((size_t) 1, output.at(1).inputs.size());
|
||||
EXPECT_EQ("four", output.at(1).inputs.at(0));
|
||||
}
|
||||
|
||||
@ -59,15 +59,15 @@ TEST(StringBased, Quotes) {
|
||||
|
||||
auto output = CLI::detail::parse_ini(ofile);
|
||||
|
||||
EXPECT_EQ(3, output.size());
|
||||
EXPECT_EQ((size_t) 3, output.size());
|
||||
EXPECT_EQ("one", output.at(0).name());
|
||||
EXPECT_EQ(1, output.at(0).inputs.size());
|
||||
EXPECT_EQ((size_t) 1, output.at(0).inputs.size());
|
||||
EXPECT_EQ("three", output.at(0).inputs.at(0));
|
||||
EXPECT_EQ("two", output.at(1).name());
|
||||
EXPECT_EQ(1, output.at(1).inputs.size());
|
||||
EXPECT_EQ((size_t) 1, output.at(1).inputs.size());
|
||||
EXPECT_EQ("four", output.at(1).inputs.at(0));
|
||||
EXPECT_EQ("five", output.at(2).name());
|
||||
EXPECT_EQ(1, output.at(2).inputs.size());
|
||||
EXPECT_EQ((size_t) 1, output.at(2).inputs.size());
|
||||
EXPECT_EQ("six and seven", output.at(2).inputs.at(0));
|
||||
}
|
||||
|
||||
@ -82,15 +82,15 @@ TEST(StringBased, Vector) {
|
||||
|
||||
auto output = CLI::detail::parse_ini(ofile);
|
||||
|
||||
EXPECT_EQ(3, output.size());
|
||||
EXPECT_EQ((size_t) 3, output.size());
|
||||
EXPECT_EQ("one", output.at(0).name());
|
||||
EXPECT_EQ(1, output.at(0).inputs.size());
|
||||
EXPECT_EQ((size_t) 1, output.at(0).inputs.size());
|
||||
EXPECT_EQ("three", output.at(0).inputs.at(0));
|
||||
EXPECT_EQ("two", output.at(1).name());
|
||||
EXPECT_EQ(1, output.at(1).inputs.size());
|
||||
EXPECT_EQ((size_t) 1, output.at(1).inputs.size());
|
||||
EXPECT_EQ("four", output.at(1).inputs.at(0));
|
||||
EXPECT_EQ("five", output.at(2).name());
|
||||
EXPECT_EQ(3, output.at(2).inputs.size());
|
||||
EXPECT_EQ((size_t) 3, output.at(2).inputs.size());
|
||||
EXPECT_EQ("six", output.at(2).inputs.at(0));
|
||||
EXPECT_EQ("and", output.at(2).inputs.at(1));
|
||||
EXPECT_EQ("seven", output.at(2).inputs.at(2));
|
||||
@ -107,12 +107,12 @@ TEST(StringBased, Spaces) {
|
||||
|
||||
auto output = CLI::detail::parse_ini(ofile);
|
||||
|
||||
EXPECT_EQ(2, output.size());
|
||||
EXPECT_EQ((size_t) 2, output.size());
|
||||
EXPECT_EQ("one", output.at(0).name());
|
||||
EXPECT_EQ(1, output.at(0).inputs.size());
|
||||
EXPECT_EQ((size_t) 1, output.at(0).inputs.size());
|
||||
EXPECT_EQ("three", output.at(0).inputs.at(0));
|
||||
EXPECT_EQ("two", output.at(1).name());
|
||||
EXPECT_EQ(1, output.at(1).inputs.size());
|
||||
EXPECT_EQ((size_t) 1, output.at(1).inputs.size());
|
||||
EXPECT_EQ("four", output.at(1).inputs.at(0));
|
||||
}
|
||||
|
||||
@ -127,13 +127,13 @@ TEST(StringBased, Sections) {
|
||||
|
||||
auto output = CLI::detail::parse_ini(ofile);
|
||||
|
||||
EXPECT_EQ(2, output.size());
|
||||
EXPECT_EQ((size_t) 2, output.size());
|
||||
EXPECT_EQ("one", output.at(0).name());
|
||||
EXPECT_EQ(1, output.at(0).inputs.size());
|
||||
EXPECT_EQ((size_t) 1, output.at(0).inputs.size());
|
||||
EXPECT_EQ("three", output.at(0).inputs.at(0));
|
||||
EXPECT_EQ("two", output.at(1).name());
|
||||
EXPECT_EQ("second", output.at(1).parent());
|
||||
EXPECT_EQ(1, output.at(1).inputs.size());
|
||||
EXPECT_EQ((size_t) 1, output.at(1).inputs.size());
|
||||
EXPECT_EQ("four", output.at(1).inputs.at(0));
|
||||
}
|
||||
|
||||
@ -151,13 +151,13 @@ TEST(StringBased, SpacesSections) {
|
||||
|
||||
auto output = CLI::detail::parse_ini(ofile);
|
||||
|
||||
EXPECT_EQ(2, output.size());
|
||||
EXPECT_EQ((size_t) 2, output.size());
|
||||
EXPECT_EQ("one", output.at(0).name());
|
||||
EXPECT_EQ(1, output.at(0).inputs.size());
|
||||
EXPECT_EQ((size_t) 1, output.at(0).inputs.size());
|
||||
EXPECT_EQ("three", output.at(0).inputs.at(0));
|
||||
EXPECT_EQ("two", output.at(1).name());
|
||||
EXPECT_EQ("second", output.at(1).parent());
|
||||
EXPECT_EQ(1, output.at(1).inputs.size());
|
||||
EXPECT_EQ((size_t) 1, output.at(1).inputs.size());
|
||||
EXPECT_EQ("four", output.at(1).inputs.at(0));
|
||||
}
|
||||
|
||||
@ -345,7 +345,7 @@ TEST_F(TApp, IniSubFailure) {
|
||||
|
||||
TempFile tmpini{"TestIniTmp.ini"};
|
||||
|
||||
auto sub = app.add_subcommand("other");
|
||||
app.add_subcommand("other");
|
||||
app.add_config("--config", tmpini);
|
||||
|
||||
{
|
||||
|
@ -5,7 +5,7 @@ TEST_F(TApp, BasicSubcommands) {
|
||||
auto sub2 = app.add_subcommand("sub2");
|
||||
|
||||
run();
|
||||
EXPECT_EQ(0, app.get_subcommands().size());
|
||||
EXPECT_EQ((size_t) 0, app.get_subcommands().size());
|
||||
|
||||
app.reset();
|
||||
args = {"sub1"};
|
||||
@ -13,7 +13,7 @@ TEST_F(TApp, BasicSubcommands) {
|
||||
EXPECT_EQ(sub1, app.get_subcommands().at(0));
|
||||
|
||||
app.reset();
|
||||
EXPECT_EQ(0, app.get_subcommands().size());
|
||||
EXPECT_EQ((size_t) 0, app.get_subcommands().size());
|
||||
|
||||
args = {"sub2"};
|
||||
run();
|
||||
@ -271,7 +271,7 @@ TEST_F(SubcommandProgram, Multiple) {
|
||||
args = {"-d", "start", "-ffilename", "stop"};
|
||||
|
||||
run();
|
||||
EXPECT_EQ(2, app.get_subcommands().size());
|
||||
EXPECT_EQ((size_t) 2, app.get_subcommands().size());
|
||||
EXPECT_EQ(1, dummy);
|
||||
EXPECT_EQ("filename", file);
|
||||
}
|
||||
@ -287,7 +287,7 @@ TEST_F(SubcommandProgram, MultipleArgs) {
|
||||
|
||||
run();
|
||||
|
||||
EXPECT_EQ(2, app.get_subcommands().size());
|
||||
EXPECT_EQ((size_t) 2, app.get_subcommands().size());
|
||||
|
||||
}
|
||||
|
||||
@ -316,7 +316,7 @@ TEST_F(TApp, SubcomInheritCaseCheck) {
|
||||
auto sub2 = app.add_subcommand("sub2");
|
||||
|
||||
run();
|
||||
EXPECT_EQ(0, app.get_subcommands().size());
|
||||
EXPECT_EQ((size_t) 0, app.get_subcommands().size());
|
||||
|
||||
app.reset();
|
||||
args = {"SuB1"};
|
||||
@ -324,7 +324,7 @@ TEST_F(TApp, SubcomInheritCaseCheck) {
|
||||
EXPECT_EQ(sub1, app.get_subcommands().at(0));
|
||||
|
||||
app.reset();
|
||||
EXPECT_EQ(0, app.get_subcommands().size());
|
||||
EXPECT_EQ((size_t) 0, app.get_subcommands().size());
|
||||
|
||||
args = {"sUb2"};
|
||||
run();
|
||||
|
Loading…
x
Reference in New Issue
Block a user