Skip to content

Commit 33484b3

Browse files
authored
install_dir key and better config error handling (#178)
1 parent 624f522 commit 33484b3

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

cli/commands/config.cc

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,17 @@ constexpr auto USAGE = R"(Ecsact Config Command
1717
ecsact config [<keys>...]
1818
1919
Options:
20-
--include_dir
21-
Prints the include directory containing Ecsact headers.
22-
--plugin_dir
23-
Prints the directory containing all built-in Ecsact codegen plugins.
24-
--builtin_plugins
25-
Prints a list of built-in Ecsact codegen plugins available.
20+
<keys>
21+
Configuration keys. When 1 key is provided the config value for that key is
22+
printed to stdout. If no keys or more than 1 key is provided then a JSON
23+
object is printed to stdout.
24+
25+
Available config keys:
26+
install_dir directory Ecsact SDK was installed to
27+
include_dir directory containing Ecsact headers
28+
plugin_dir directory containing built-in Ecsact codegen plugins
29+
builtin_plugins list of built-in Ecsact codegen plugins available.
30+
2631
)";
2732

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

6267
std::unordered_map<std::string, std::function<int()>> key_handlers{
68+
{
69+
"install_dir",
70+
[&] {
71+
output["install_dir"] = install_prefix.string();
72+
return 0;
73+
},
74+
},
6375
{
6476
"include_dir",
6577
[&] {
@@ -129,6 +141,12 @@ int ecsact::cli::detail::config_command(int argc, char* argv[]) {
129141
}
130142
} else {
131143
for(auto key : keys) {
144+
if(!key_handlers.contains(key)) {
145+
std::cerr << "[ERROR] Invalid config key: " << key << "\n\n";
146+
std::cerr << USAGE;
147+
return 1;
148+
}
149+
132150
int exit_code = key_handlers.at(key)();
133151
if(exit_code != 0) {
134152
return exit_code;

0 commit comments

Comments
 (0)