Skip to content

Commit f37242f

Browse files
authored
Added outdir codegen flag (#14)
1 parent abed463 commit f37242f

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

cli/commands/codegen.cc

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,17 @@ constexpr auto USAGE = R"(Ecsact Codegen Command
2727
2828
Usage:
2929
ecsact codegen <files> --plugin=<plugin> [--stdout]
30-
ecsact codegen <files>... --plugin=<plugin>...
30+
ecsact codegen <files>... --plugin=<plugin>... [--outdir=<directory>]
3131
3232
Options:
3333
-p, --plugin=<plugin>
3434
Name of bundled plugin or path to plugin.
3535
--stdout
3636
Print to stdout instead of writing to a file. May only be used if a single
3737
ecsact file and single ecsact codegen plugin are used.
38+
-o, --outdir=<directory>
39+
Specify directory generated files should be written to. By default generated
40+
files are written next to source files.
3841
)";
3942

4043
static fs::path get_default_plugins_dir() {
@@ -220,6 +223,21 @@ int ecsact::cli::detail::codegen_command(int argc, char* argv[]) {
220223
set_meta_fn_ptr(#fn_name, &::fn_name)
221224
FOR_EACH_ECSACT_META_API_FN(CALL_SET_META_FN_PTR);
222225

226+
std::optional<fs::path> outdir;
227+
if(args.at("--outdir").isString()) {
228+
outdir = fs::path(args.at("--outdir").asString());
229+
if(!fs::exists(*outdir)) {
230+
std::error_code ec;
231+
fs::create_directories(*outdir, ec);
232+
if(ec) {
233+
std::cerr
234+
<< "[ERROR] Failed to create out directory "
235+
<< outdir->string() << ": " << ec.message() << "\n";
236+
return 3;
237+
}
238+
}
239+
}
240+
223241
for(auto package_id : package_ids) {
224242
fs::path output_file_path = ecsact_meta_package_file_path(package_id);
225243
if(output_file_path.empty()) {
@@ -232,6 +250,11 @@ int ecsact::cli::detail::codegen_command(int argc, char* argv[]) {
232250
output_file_path.replace_extension(
233251
output_file_path.extension().string() + "." + plugin_name
234252
);
253+
254+
if(outdir) {
255+
output_file_path = *outdir / output_file_path.filename();
256+
}
257+
235258
if(output_paths.contains(output_file_path.string())) {
236259
has_plugin_error = true;
237260
std::cerr

0 commit comments

Comments
 (0)