Skip to content

install_dir key and better config error handling #178

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 29, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 24 additions & 6 deletions cli/commands/config.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,17 @@ constexpr auto USAGE = R"(Ecsact Config Command
ecsact config [<keys>...]

Options:
--include_dir
Prints the include directory containing Ecsact headers.
--plugin_dir
Prints the directory containing all built-in Ecsact codegen plugins.
--builtin_plugins
Prints a list of built-in Ecsact codegen plugins available.
<keys>
Configuration keys. When 1 key is provided the config value for that key is
printed to stdout. If no keys or more than 1 key is provided then a JSON
object is printed to stdout.

Available config keys:
install_dir directory Ecsact SDK was installed to
include_dir directory containing Ecsact headers
plugin_dir directory containing built-in Ecsact codegen plugins
builtin_plugins list of built-in Ecsact codegen plugins available.

)";

constexpr auto CANNOT_FIND_INCLUDE_DIR = R"(
Expand Down Expand Up @@ -60,6 +65,13 @@ int ecsact::cli::detail::config_command(int argc, char* argv[]) {
auto output = "{}"_json;

std::unordered_map<std::string, std::function<int()>> key_handlers{
{
"install_dir",
[&] {
output["install_dir"] = install_prefix.string();
return 0;
},
},
{
"include_dir",
[&] {
Expand Down Expand Up @@ -129,6 +141,12 @@ int ecsact::cli::detail::config_command(int argc, char* argv[]) {
}
} else {
for(auto key : keys) {
if(!key_handlers.contains(key)) {
std::cerr << "[ERROR] Invalid config key: " << key << "\n\n";
std::cerr << USAGE;
return 1;
}

int exit_code = key_handlers.at(key)();
if(exit_code != 0) {
return exit_code;
Expand Down