Skip to content

Commit bef0095

Browse files
committed
feat: add --format flag
Signed-off-by: Andrew Steurer <94206073+asteurer@users.noreply.github.com>
1 parent 32b491d commit bef0095

4 files changed

Lines changed: 15 additions & 2 deletions

File tree

examples/wasip2/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
generate-bindings:
2-
componentize-go --world wasip2-example bindings
2+
componentize-go --world wasip2-example bindings --format
33

44
build-component: generate-bindings
55
componentize-go --world wasip2-example componentize

examples/wasip3/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ $(GO)/bin/go:
55
tar xf $(GO).tbz
66

77
generate-bindings:
8-
componentize-go --world wasip3-example bindings
8+
componentize-go --world wasip3-example bindings --format
99

1010
build-component: generate-bindings $(GO)/bin/go
1111
componentize-go --world wasip3-example componentize --go $(GO)/bin/go

src/bindings.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,21 @@ pub fn generate_bindings(
88
features: &[String],
99
all_features: bool,
1010
generate_stubs: bool,
11+
should_format: bool,
1112
output: Option<&Path>,
1213
) -> Result<()> {
1314
let (resolve, world) = parse_wit(wit_path, world, features, all_features)?;
1415
let mut files = Default::default();
1516

17+
let format = if should_format {
18+
wit_bindgen_go::Format::True
19+
} else {
20+
wit_bindgen_go::Format::False
21+
};
22+
1623
wit_bindgen_go::Opts {
1724
generate_stubs,
25+
format,
1826
..Default::default()
1927
}
2028
.build()

src/command.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ pub struct Bindings {
8989
/// A stub function is a placeholder method which has not yet been implemented.
9090
#[arg(long)]
9191
pub generate_stubs: bool,
92+
93+
#[arg(long)]
94+
/// Whether or not `gofmt` should be used (if present) to format generated code.
95+
pub format: bool,
9296
}
9397

9498
fn componentize(common: Common, componentize: Componentize) -> Result<()> {
@@ -120,6 +124,7 @@ fn bindings(common: Common, bindings: Bindings) -> Result<()> {
120124
&common.features,
121125
common.all_features,
122126
bindings.generate_stubs,
127+
bindings.format,
123128
bindings.output.as_deref(),
124129
)
125130
}

0 commit comments

Comments
 (0)