Squashed 'libs/CommService/' content from commit 7ccc0fc
git-subtree-dir: libs/CommService git-subtree-split: 7ccc0fce88bbc5969df060058cf0fb57abe3bcf9
This commit is contained in:
32
libs/CLI11/book/code/CMakeLists.txt
Normal file
32
libs/CLI11/book/code/CMakeLists.txt
Normal file
@@ -0,0 +1,32 @@
|
||||
cmake_minimum_required(VERSION 3.11)
|
||||
|
||||
project(CLI11_Examples LANGUAGES CXX)
|
||||
|
||||
# Using CMake 3.11's ability to set imported interface targets
|
||||
add_library(CLI11::CLI11 IMPORTED INTERFACE)
|
||||
target_include_directories(CLI11::CLI11 INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/../../include")
|
||||
target_compile_features(CLI11::CLI11 INTERFACE cxx_std_11)
|
||||
|
||||
# Add CTest
|
||||
enable_testing()
|
||||
|
||||
# Quick function to add the base executable
|
||||
function(add_cli_exe NAME)
|
||||
add_executable(${NAME} ${NAME}.cpp)
|
||||
target_link_libraries(${NAME} CLI11::CLI11)
|
||||
endfunction()
|
||||
|
||||
add_cli_exe(simplest)
|
||||
add_test(NAME simplest COMMAND simplest)
|
||||
|
||||
add_cli_exe(intro)
|
||||
add_test(NAME intro COMMAND intro)
|
||||
add_test(NAME intro_p COMMAND intro -p 5)
|
||||
|
||||
add_cli_exe(flags)
|
||||
add_test(NAME flags COMMAND flags)
|
||||
add_test(NAME flags_bip COMMAND flags -b -i -p)
|
||||
|
||||
add_cli_exe(geet)
|
||||
add_test(NAME geet_add COMMAND geet add)
|
||||
add_test(NAME geet_commit COMMAND geet commit -m "Test")
|
||||
36
libs/CLI11/book/code/flags.cpp
Normal file
36
libs/CLI11/book/code/flags.cpp
Normal file
@@ -0,0 +1,36 @@
|
||||
#include "CLI/CLI.hpp"
|
||||
#include <iostream>
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
CLI::App app{"Flag example program"};
|
||||
|
||||
/// [define]
|
||||
bool flag_bool;
|
||||
app.add_flag("--bool,-b", flag_bool, "This is a bool flag");
|
||||
|
||||
int flag_int;
|
||||
app.add_flag("-i,--int", flag_int, "This is an int flag");
|
||||
|
||||
CLI::Option *flag_plain = app.add_flag("--plain,-p", "This is a plain flag");
|
||||
/// [define]
|
||||
|
||||
/// [parser]
|
||||
try {
|
||||
app.parse(argc, argv);
|
||||
} catch(const CLI::ParseError &e) {
|
||||
return app.exit(e);
|
||||
}
|
||||
/// [parser]
|
||||
|
||||
/// [usage]
|
||||
cout << "The flags program" << endl;
|
||||
if(flag_bool)
|
||||
cout << "Bool flag passed" << endl;
|
||||
if(flag_int > 0)
|
||||
cout << "Flag int: " << flag_int << endl;
|
||||
if(*flag_plain)
|
||||
cout << "Flag plain: " << flag_plain->count() << endl;
|
||||
/// [usage]
|
||||
}
|
||||
50
libs/CLI11/book/code/geet.cpp
Normal file
50
libs/CLI11/book/code/geet.cpp
Normal file
@@ -0,0 +1,50 @@
|
||||
#include "CLI/CLI.hpp"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
|
||||
/// [Intro]
|
||||
CLI::App app{"Geet, a command line git lookalike that does nothing"};
|
||||
app.require_subcommand(1);
|
||||
/// [Intro]
|
||||
|
||||
/// [Add]
|
||||
auto add = app.add_subcommand("add", "Add file(s)");
|
||||
|
||||
bool add_update;
|
||||
add->add_flag("-u,--update", add_update, "Add updated files only");
|
||||
|
||||
std::vector<std::string> add_files;
|
||||
add->add_option("files", add_files, "Files to add");
|
||||
|
||||
add->callback([&]() {
|
||||
std::cout << "Adding:";
|
||||
if(add_files.empty()) {
|
||||
if(add_update)
|
||||
std::cout << " all updated files";
|
||||
else
|
||||
std::cout << " all files";
|
||||
} else {
|
||||
for(auto file : add_files)
|
||||
std::cout << " " << file;
|
||||
}
|
||||
});
|
||||
/// [Add]
|
||||
|
||||
/// [Commit]
|
||||
auto commit = app.add_subcommand("commit", "Commit files");
|
||||
|
||||
std::string commit_message;
|
||||
commit->add_option("-m,--message", commit_message, "A message")->required();
|
||||
|
||||
commit->callback([&]() { std::cout << "Commit message: " << commit_message; });
|
||||
/// [Commit]
|
||||
|
||||
/// [Parse]
|
||||
CLI11_PARSE(app, argc, argv);
|
||||
|
||||
std::cout << "\nThanks for using geet!\n" << std::endl;
|
||||
return 0;
|
||||
/// [Parse]
|
||||
}
|
||||
15
libs/CLI11/book/code/intro.cpp
Normal file
15
libs/CLI11/book/code/intro.cpp
Normal file
@@ -0,0 +1,15 @@
|
||||
#include "CLI/CLI.hpp"
|
||||
#include <iostream>
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
CLI::App app{"App description"};
|
||||
|
||||
// Define options
|
||||
int p = 0;
|
||||
app.add_option("-p", p, "Parameter");
|
||||
|
||||
CLI11_PARSE(app, argc, argv);
|
||||
|
||||
std::cout << "Parameter value: " << p << std::endl;
|
||||
return 0;
|
||||
}
|
||||
11
libs/CLI11/book/code/simplest.cpp
Normal file
11
libs/CLI11/book/code/simplest.cpp
Normal file
@@ -0,0 +1,11 @@
|
||||
#include "CLI/CLI.hpp"
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
CLI::App app;
|
||||
|
||||
// Add new options/flags here
|
||||
|
||||
CLI11_PARSE(app, argc, argv);
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user