forked from OpenEnroth/OpenEnroth
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ad2b79c
commit 8038505
Showing
13 changed files
with
90 additions
and
100 deletions.
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
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
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
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,11 @@ | ||
cmake_minimum_required(VERSION 3.21.1) | ||
|
||
set(LIBRARY_CLI_SOURCES | ||
Cli.cpp) | ||
|
||
set(LIBRARY_CLI_HEADERS | ||
Cli.h) | ||
|
||
add_library(library_cli ${LIBRARY_CLI_SOURCES} ${LIBRARY_CLI_HEADERS}) | ||
target_link_libraries(library_cli CLI11::CLI11) | ||
target_check_style(library_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,18 @@ | ||
#include "Cli.h" | ||
|
||
void CliApp::parse(int argc, const char *const *argv, bool *helpPrinted) { | ||
// Note: we don't call base_type::ensure_utf8 here, it's the caller's responsibility. | ||
try { | ||
base_type::parse(argc, argv); | ||
} catch (const CLI::CallForHelp &e) { | ||
base_type::exit(e); | ||
*helpPrinted = true; | ||
} catch (const CLI::CallForAllHelp &e) { | ||
base_type::exit(e); | ||
*helpPrinted = true; | ||
} catch (const CLI::CallForVersion &e) { | ||
base_type::exit(e); | ||
*helpPrinted = true; | ||
} | ||
// Other exception are propagated. | ||
} |
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 @@ | ||
#pragma once | ||
|
||
#include <utility> | ||
#include <string> | ||
|
||
#include <CLI/CLI.hpp> | ||
|
||
/** | ||
* A thin wrapper around `CLI:App` that simplifies the code for our use cases. | ||
*/ | ||
class CliApp : public CLI::App { | ||
using base_type = CLI::App; | ||
public: | ||
CliApp() = default; | ||
|
||
template<class SubcommandEnum> | ||
CliApp *add_subcommand(std::string name, std::string description, SubcommandEnum &target, SubcommandEnum targetValue) { | ||
auto callback = [target = &target, targetValue] { | ||
*target = targetValue; | ||
}; | ||
return static_cast<CliApp *>(base_type::add_subcommand(std::move(name), std::move(description))->callback(std::move(callback))); | ||
} | ||
|
||
void parse(int argc, const char *const *argv, bool *helpPrinted); | ||
}; |
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
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