Skip to content

Commit

Permalink
feat: Support custom class name for trace file. (#272)
Browse files Browse the repository at this point in the history
This allows a custom class name to be used in place of `Trace.java` when
desired.
  • Loading branch information
DavePearce committed Oct 15, 2024
1 parent 0d0b53b commit 6c057df
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
11 changes: 9 additions & 2 deletions src/exporters/besu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ struct BesuConstant {
}
#[derive(Serialize)]
struct TemplateData {
class: String,
module: String,
module_prefix: String,
columns: Vec<BesuColumn>,
Expand Down Expand Up @@ -201,7 +202,12 @@ fn perspectivize_name(h: &Handle, p: &str) -> String {
)
}

pub fn render(cs: &ConstraintSet, package: &str, output_path: Option<&String>) -> Result<()> {
pub fn render(
cs: &ConstraintSet,
package: &str,
class: &str,
output_path: Option<&String>,
) -> Result<()> {
let registers = cs
.columns
.registers
Expand Down Expand Up @@ -277,6 +283,7 @@ pub fn render(cs: &ConstraintSet, package: &str, output_path: Option<&String>) -
handlebars.register_escape_fn(handlebars::no_escape);

let template_data = TemplateData {
class: class.to_owned(),
module: package.to_owned(),
module_prefix: package.to_case(Case::Pascal),
constants,
Expand All @@ -294,7 +301,7 @@ pub fn render(cs: &ConstraintSet, package: &str, output_path: Option<&String>) -
bail!("{} is not a directory", f.bold().yellow());
}

let trace_columns_java_filepath = Path::new(f).join("Trace.java");
let trace_columns_java_filepath = Path::new(f).join(format!("{class}.java"));

File::create(&trace_columns_java_filepath)?
.write_all(trace_columns_render.as_bytes())
Expand Down
2 changes: 1 addition & 1 deletion src/exporters/besu_trace_columns.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
* <p>Any modifications to this code may be overwritten and could lead to unexpected behavior.
* Please DO NOT ATTEMPT TO MODIFY this code directly.
*/
public class Trace {
public class {{ class }} {
{{#each constants}}
public static final {{ this.tupe }} {{ this.name }} = {{ this.value }};
{{/each}}
Expand Down
10 changes: 10 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,14 @@ enum Commands {
)]
package: String,

#[arg(
short = 'c',
long = "class",
default_value = "Trace",
help = "class name for generated trace file"
)]
class: String,

#[arg(short = 'o', long = "out", help = "where to render the columns")]
output_file_path: Option<String>,
},
Expand Down Expand Up @@ -674,11 +682,13 @@ fn main() -> Result<()> {
#[cfg(feature = "exporters")]
Commands::Besu {
package,
class,
output_file_path: output_path,
} => {
exporters::besu::render(
&builder.into_constraint_set()?,
&package,
&class,
output_path.as_ref(),
)?;
}
Expand Down

0 comments on commit 6c057df

Please sign in to comment.