@@ -26,7 +26,7 @@ constexpr auto file_readonly_perms =
2626constexpr auto USAGE = R"( Ecsact Codegen Command
2727
2828Usage:
29- ecsact codegen <files> --plugin=<plugin> [--stdout]
29+ ecsact codegen <files>... --plugin=<plugin> [--stdout]
3030 ecsact codegen <files>... --plugin=<plugin>... [--outdir=<directory>]
3131
3232Options:
@@ -238,42 +238,47 @@ int ecsact::cli::detail::codegen_command(int argc, char* argv[]) {
238238 }
239239 }
240240
241- for (auto package_id : package_ids) {
242- fs::path output_file_path = ecsact_meta_package_file_path (package_id);
243- if (output_file_path.empty ()) {
244- std::cerr
245- << " [ERROR] Could not find package source file path from "
246- << " 'ecsact_meta_package_file_path'\n " ;
247- continue ;
248- }
241+ if (args.at (" --stdout" ).asBool ()) {
242+ plugin_fn (*package_ids.begin (), &stdout_write_fn);
243+ std::cout.flush ();
244+ } else {
245+ for (auto package_id : package_ids) {
246+ fs::path output_file_path = ecsact_meta_package_file_path (package_id);
247+ if (output_file_path.empty ()) {
248+ std::cerr
249+ << " [ERROR] Could not find package source file path from "
250+ << " 'ecsact_meta_package_file_path'\n " ;
251+ continue ;
252+ }
249253
250- output_file_path.replace_extension (
251- output_file_path.extension ().string () + " ." + plugin_name
252- );
254+ output_file_path.replace_extension (
255+ output_file_path.extension ().string () + " ." + plugin_name
256+ );
253257
254- if (outdir) {
255- output_file_path = *outdir / output_file_path.filename ();
256- }
258+ if (outdir) {
259+ output_file_path = *outdir / output_file_path.filename ();
260+ }
257261
258- if (output_paths.contains (output_file_path.string ())) {
259- has_plugin_error = true ;
260- std::cerr
261- << " [ERROR] Plugin '"
262- << plugin.location ().filename ().string ()
263- << " ' has conflicts with another plugin output file '"
264- << output_file_path.string () << " '\n " ;
265- continue ;
266- }
262+ if (output_paths.contains (output_file_path.string ())) {
263+ has_plugin_error = true ;
264+ std::cerr
265+ << " [ERROR] Plugin '"
266+ << plugin.location ().filename ().string ()
267+ << " ' has conflicts with another plugin output file '"
268+ << output_file_path.string () << " '\n " ;
269+ continue ;
270+ }
267271
268- output_paths.emplace (output_file_path.string ());
269- if (fs::exists (output_file_path)) {
270- fs::permissions (output_file_path, fs::perms::all);
272+ output_paths.emplace (output_file_path.string ());
273+ if (fs::exists (output_file_path)) {
274+ fs::permissions (output_file_path, fs::perms::all);
275+ }
276+ file_write_stream.open (output_file_path);
277+ plugin_fn (package_id, &file_write_fn);
278+ file_write_stream.flush ();
279+ file_write_stream.close ();
280+ fs::permissions (output_file_path, file_readonly_perms);
271281 }
272- file_write_stream.open (output_file_path);
273- plugin_fn (package_id, &file_write_fn);
274- file_write_stream.flush ();
275- file_write_stream.close ();
276- fs::permissions (output_file_path, file_readonly_perms);
277282 }
278283
279284 plugin.unload ();
0 commit comments