Skip to content

Commit c371864

Browse files
committed
Support code additions
Add .rs files next to the CRD .yaml file and the code will be added to the resulting Rust code Signed-off-by: Sebastian Hoß <[email protected]>
1 parent 3545798 commit c371864

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

code-generator/src/bin/custom_resource_generator.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ use code_generator::{group_name, kind_name, last_path_segment, path_contains};
55
use glob::glob;
66
use std::process::{Command, Stdio};
77
use std::{env, fs};
8+
use std::fs::OpenOptions;
9+
use std::io::Write;
810

911
fn main() {
1012
let args: Vec<String> = env::args().collect();
@@ -69,6 +71,18 @@ fn main() {
6971

7072
fs::write(&resource_target, output.stdout)
7173
.expect("should be able to write custom resource");
74+
75+
let code_file = path.with_extension("rs");
76+
if code_file.exists() {
77+
let additional_code = fs::read(code_file).expect("reading file with additional code failed");
78+
let mut generated_file = OpenOptions::new()
79+
.append(true)
80+
.open(resource_target)
81+
.expect("cannot target resource file");
82+
generated_file
83+
.write(&additional_code)
84+
.expect("writing to target resource file failed");
85+
}
7286
}
7387
}
7488
}

0 commit comments

Comments
 (0)