@@ -36,29 +36,40 @@ using ecsact::cli::warning_message;
36
36
#endif
37
37
38
38
namespace {
39
- auto print_text_report (const alert_message& msg) -> void {
40
- std::cout << std::format ( //
39
+ constexpr auto get_outputstream (auto && stream, auto && preferred)
40
+ -> decltype(auto ) {
41
+ if constexpr (std::is_same_v<
42
+ std::nullptr_t ,
43
+ std::remove_cvref_t <decltype (stream)>>) {
44
+ return preferred;
45
+ } else {
46
+ return stream;
47
+ }
48
+ }
49
+
50
+ auto print_text_report (auto && output, const alert_message& msg) -> void {
51
+ get_outputstream (output, std::cout) << std::format ( //
41
52
COLOR_RED " ALERT:" COLOR_RESET " {}\n " ,
42
53
msg.content
43
54
);
44
55
}
45
56
46
- auto print_text_report (const info_message& msg) -> void {
47
- std::cout << std::format ( //
57
+ auto print_text_report (auto && output, const info_message& msg) -> void {
58
+ get_outputstream (output, std::cout) << std::format ( //
48
59
COLOR_GRN " INFO:" COLOR_RESET " {}\n " ,
49
60
msg.content
50
61
);
51
62
}
52
63
53
- auto print_text_report (const error_message& msg) -> void {
54
- std::cout << std::format ( //
64
+ auto print_text_report (auto && output, const error_message& msg) -> void {
65
+ get_outputstream (output, std::cerr) << std::format ( //
55
66
COLOR_RED " ERROR:" COLOR_RESET " {}\n " ,
56
67
msg.content
57
68
);
58
69
}
59
70
60
- auto print_text_report (const ecsact_error_message& msg) -> void {
61
- std::cerr << std::format ( //
71
+ auto print_text_report (auto && output, const ecsact_error_message& msg) -> void {
72
+ get_outputstream (output, std::cerr) << std::format ( //
62
73
COLOR_RED " ERROR:" COLOR_RESET " {}:{}:{}\n {}\n " ,
63
74
msg.ecsact_source_path ,
64
75
msg.line ,
@@ -67,31 +78,34 @@ auto print_text_report(const ecsact_error_message& msg) -> void {
67
78
);
68
79
}
69
80
70
- auto print_text_report (const warning_message& msg) -> void {
71
- std::cout << std::format ( //
81
+ auto print_text_report (auto && output, const warning_message& msg) -> void {
82
+ get_outputstream (output, std::cout) << std::format ( //
72
83
COLOR_YEL " WARNING:" COLOR_RESET " {}\n " ,
73
84
msg.content
74
85
);
75
86
}
76
87
77
- auto print_text_report (const success_message& msg) -> void {
78
- std::cout << std::format ( //
88
+ auto print_text_report (auto && output, const success_message& msg) -> void {
89
+ get_outputstream (output, std::cout) << std::format ( //
79
90
COLOR_GRN " SUCCESS:" COLOR_RESET " {}\n " ,
80
91
msg.content
81
92
);
82
93
}
83
94
84
- auto print_text_report (const module_methods_message& msg) -> void {
85
- std::cout << " MODULE METHODS FOR " << msg.module_name << " :\n " ;
95
+ auto print_text_report (auto && output, const module_methods_message& msg)
96
+ -> void {
97
+ get_outputstream (output, std::cout)
98
+ << " MODULE METHODS FOR " << msg.module_name << " :\n " ;
86
99
for (auto & method : msg.methods ) {
87
100
std::cout //
88
101
<< " " << (method.available ? COLOR_GRN " YES " : COLOR_RED " NO " )
89
102
<< COLOR_RESET << method.method_name << " \n " ;
90
103
}
91
104
}
92
105
93
- auto print_text_report (const subcommand_start_message& msg) -> void {
94
- std::cout << std::format ( //
106
+ auto print_text_report (auto && output, const subcommand_start_message& msg)
107
+ -> void {
108
+ get_outputstream (output, std::cout) << std::format ( //
95
109
COLOR_BLU " SUBCOMMAND({}) START >>" COLOR_RESET " {} " ,
96
110
msg.id ,
97
111
msg.executable
@@ -102,32 +116,36 @@ auto print_text_report(const subcommand_start_message& msg) -> void {
102
116
std::cout << " \n " ;
103
117
}
104
118
105
- auto print_text_report (const subcommand_stdout_message& msg) -> void {
106
- std::cout << std::format ( //
119
+ auto print_text_report (auto && output, const subcommand_stdout_message& msg)
120
+ -> void {
121
+ get_outputstream (output, std::cout) << std::format ( //
107
122
COLOR_BLU " SUBCOMMAND({}) STDOUT:" COLOR_RESET " {}\n " ,
108
123
msg.id ,
109
124
msg.line
110
125
);
111
126
}
112
127
113
- auto print_text_report (const subcommand_stderr_message& msg) -> void {
114
- std::cout << std::format ( //
128
+ auto print_text_report (auto && output, const subcommand_stderr_message& msg)
129
+ -> void {
130
+ get_outputstream (output, std::cout) << std::format ( //
115
131
COLOR_RED " SUBCOMMAND({}) STDERR:" COLOR_RESET " {}\n " ,
116
132
msg.id ,
117
133
msg.line
118
134
);
119
135
}
120
136
121
- auto print_text_report (const subcommand_progress_message& msg) -> void {
122
- std::cout << std::format ( //
137
+ auto print_text_report (auto && output, const subcommand_progress_message& msg)
138
+ -> void {
139
+ get_outputstream (output, std::cout) << std::format ( //
123
140
COLOR_BLU " SUBCOMMAND({}) PROG:" COLOR_RESET " {}\n " ,
124
141
msg.id ,
125
142
msg.description
126
143
);
127
144
}
128
145
129
- auto print_text_report (const subcommand_end_message& msg) -> void {
130
- std::cout << std::format ( //
146
+ auto print_text_report (auto && output, const subcommand_end_message& msg)
147
+ -> void {
148
+ get_outputstream (output, std::cout) << std::format ( //
131
149
COLOR_BLU " SUBCOMMAND({}) END << " COLOR_RESET " exit code {}\n " ,
132
150
msg.id ,
133
151
msg.exit_code
@@ -138,5 +156,17 @@ auto print_text_report(const subcommand_end_message& msg) -> void {
138
156
auto ecsact::cli::detail::text_report::operator ()( //
139
157
const message_variant_t & message
140
158
) const -> void {
141
- std::visit ([](const auto & message) { print_text_report (message); }, message);
159
+ std::visit (
160
+ [](const auto & message) { print_text_report (nullptr , message); },
161
+ message
162
+ );
163
+ }
164
+
165
+ auto ecsact::cli::detail::text_report_stderr_only::operator ()( //
166
+ const message_variant_t & message
167
+ ) const -> void {
168
+ std::visit (
169
+ [](const auto & message) { print_text_report (std::cerr, message); },
170
+ message
171
+ );
142
172
}
0 commit comments