-
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
Showing
11 changed files
with
400 additions
and
8 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#include "ecsact/cli/detail/json_report.hh" | ||
|
||
#include <iostream> | ||
#include <nlohmann/json.hpp> | ||
|
||
namespace ecsact::cli { | ||
// clang-format off | ||
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(alert_message, content) | ||
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(info_message, content) | ||
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(error_message, content) | ||
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(ecsact_error_message, ecsact_source_path, message, line, character) | ||
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(warning_message, content) | ||
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(success_message, content) | ||
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(module_methods_message::method_info, method_name, available) | ||
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(module_methods_message, module_name, methods) | ||
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(subcommand_start_message, id, executable, arguments) | ||
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(subcommand_stdout_message, id, line) | ||
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(subcommand_stderr_message, id, line) | ||
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(subcommand_progress_message, id, description) | ||
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(subcommand_end_message, id, exit_code) | ||
// clang-format on | ||
} // namespace ecsact::cli | ||
|
||
template<typename MessageT> | ||
void print_json_report(const MessageT& message) { | ||
auto message_json = "{}"_json; | ||
to_json(message_json, message); | ||
message_json["type"] = MessageT::type; | ||
std::cout << message_json.dump() + "\n"; | ||
} | ||
|
||
auto ecsact::cli::detail::json_report::operator()( // | ||
const message_variant_t& message | ||
) const -> void { | ||
std::visit([](const auto& message) { print_json_report(message); }, message); | ||
} |
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,9 @@ | ||
#pragma once | ||
|
||
#include "ecsact/cli/report_message.hh" | ||
|
||
namespace ecsact::cli::detail { | ||
struct json_report { | ||
auto operator()(const message_variant_t&) const -> void; | ||
}; | ||
} |
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,122 @@ | ||
#include "ecsact/cli/detail/text_report.hh" | ||
|
||
#include <iostream> | ||
#include <format> | ||
|
||
using ecsact::cli::alert_message; | ||
using ecsact::cli::ecsact_error_message; | ||
using ecsact::cli::error_message; | ||
using ecsact::cli::info_message; | ||
using ecsact::cli::module_methods_message; | ||
using ecsact::cli::subcommand_end_message; | ||
using ecsact::cli::subcommand_progress_message; | ||
using ecsact::cli::subcommand_start_message; | ||
using ecsact::cli::subcommand_stderr_message; | ||
using ecsact::cli::subcommand_stdout_message; | ||
using ecsact::cli::success_message; | ||
using ecsact::cli::warning_message; | ||
|
||
namespace { | ||
auto print_text_report(const alert_message& msg) -> void { | ||
std::cout << std::format( // | ||
"[ALERT] {}\n", | ||
msg.content | ||
); | ||
} | ||
|
||
auto print_text_report(const info_message& msg) -> void { | ||
std::cout << std::format( // | ||
"[INFO] {}\n", | ||
msg.content | ||
); | ||
} | ||
|
||
auto print_text_report(const error_message& msg) -> void { | ||
std::cout << std::format( // | ||
"[ERROR] {}\n", | ||
msg.content | ||
); | ||
} | ||
|
||
auto print_text_report(const ecsact_error_message& msg) -> void { | ||
std::cerr << std::format( // | ||
"[ERROR] {}:{}:{}\n" | ||
" {}\n", | ||
msg.ecsact_source_path, | ||
msg.line, | ||
msg.character, | ||
msg.message | ||
); | ||
} | ||
|
||
auto print_text_report(const warning_message& msg) -> void { | ||
std::cout << std::format( // | ||
"[WARNING] {}\n", | ||
msg.content | ||
); | ||
} | ||
|
||
auto print_text_report(const success_message& msg) -> void { | ||
std::cout << std::format( // | ||
"[SUCCESS] {}\n", | ||
msg.content | ||
); | ||
} | ||
|
||
auto print_text_report(const module_methods_message& msg) -> void { | ||
std::cout << "[Module Methods for " << msg.module_name << "]\n"; | ||
for(auto& method : msg.methods) { | ||
std::cout // | ||
<< " " << (method.available ? "YES " : " NO ") << method.method_name | ||
<< "\n"; | ||
} | ||
} | ||
|
||
auto print_text_report(const subcommand_start_message& msg) -> void { | ||
std::cout // | ||
<< "[SUBCOMMAND START id=(" << std::to_string(msg.id) << ")] " | ||
<< msg.executable << " "; | ||
for(auto& arg : msg.arguments) { | ||
std::cout << arg << " "; | ||
} | ||
std::cout << "\n"; | ||
} | ||
|
||
auto print_text_report(const subcommand_stdout_message& msg) -> void { | ||
std::cout << std::format( // | ||
"[SUBCOMMAND STDOUT id=({})] {}\n", | ||
msg.id, | ||
msg.line | ||
); | ||
} | ||
|
||
auto print_text_report(const subcommand_stderr_message& msg) -> void { | ||
std::cout << std::format( // | ||
"[SUBCOMMAND STDERR id=({})] {}\n", | ||
msg.id, | ||
msg.line | ||
); | ||
} | ||
|
||
auto print_text_report(const subcommand_progress_message& msg) -> void { | ||
std::cout << std::format( // | ||
"[SUBCOMMAND PROG id=({})] {}\n", | ||
msg.id, | ||
msg.description | ||
); | ||
} | ||
|
||
auto print_text_report(const subcommand_end_message& msg) -> void { | ||
std::cout << std::format( // | ||
"[SUBCOMMAND END id=({})] exit code {}\n", | ||
msg.id, | ||
msg.exit_code | ||
); | ||
} | ||
} // namespace | ||
|
||
auto ecsact::cli::detail::text_report::operator()( // | ||
const message_variant_t& message | ||
) const -> void { | ||
std::visit([](const auto& message) { print_text_report(message); }, message); | ||
} |
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,9 @@ | ||
#pragma once | ||
|
||
#include "ecsact/cli/report_message.hh" | ||
|
||
namespace ecsact::cli::detail { | ||
struct text_report { | ||
auto operator()(const message_variant_t&) const -> void; | ||
}; | ||
} |
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 "ecsact/cli/report.hh" | ||
|
||
static auto _report_handler = | ||
std::function<void(const ecsact::cli::message_variant_t&)>{}; | ||
|
||
auto ecsact::cli::report( // | ||
const message_variant_t& message | ||
) -> void { | ||
if(_report_handler) { | ||
_report_handler(message); | ||
} | ||
} | ||
|
||
auto ecsact::cli::set_report_handler( // | ||
std::function<void(const message_variant_t&)> handler | ||
) -> void { | ||
_report_handler = handler; | ||
} |
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,15 @@ | ||
#pragma once | ||
|
||
#include "ecsact/cli/report_message.hh" | ||
|
||
namespace ecsact::cli { | ||
|
||
auto report(const message_variant_t& message) -> void; | ||
auto set_report_handler(std::function<void(const message_variant_t&)>) -> void; | ||
|
||
template<typename StringLike> | ||
auto report_error(StringLike message) -> void { | ||
report(error_message{.content{message}}); | ||
} | ||
|
||
} // namespace ecsact::cli |
Oops, something went wrong.