Skip to content

Commit 23bcc45

Browse files
committed
Specify edition in CLI
1 parent 0af2e60 commit 23bcc45

File tree

3 files changed

+17
-12
lines changed

3 files changed

+17
-12
lines changed

proto-gen/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
<!-- next-header -->
1111
## [Unreleased] - ReleaseDate
12+
### Changed
13+
- [PR#31](https://github.com/EmbarkStudios/proto-gen/pull/31) changed the `--format` flag to take a rust edition as an argument, as previously the 2021 edition was hardcoded.
14+
1215
## [0.2.11] - 2025-01-23
1316
### Fixed
1417
- [PR#30](https://github.com/EmbarkStudios/proto-gen/pull/30) Improvements and fixes to the readme.
18+
1519
## [0.2.10] - 2025-01-16
1620
### Fixed
1721
- Update dependency `anstream` to `0.6.15` for advisory: <https://rustsec.org/advisories/RUSTSEC-2024-0404>
1822
- Build fixes that prevented v `0.2.9` from being fully released
23+
1924
## [0.2.9] - 2025-01-16
2025
### Added
2126
- [PR#27](https://github.com/EmbarkStudios/proto-gen/pull/27) Added `--prepend-header-file` option for specifying a file which will be prepended as a header in generated source files.

proto-gen/src/gen.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ pub fn run_generation(
2727
})?;
2828
let old = &proto_ws.output_dir;
2929
let new = &proto_ws.tmp_dir;
30-
if gen_opts.format {
31-
recurse_fmt(new)?;
32-
top_mod_content = fmt(&top_mod_content)?;
30+
if let Some(edition) = gen_opts.format.as_deref() {
31+
recurse_fmt(new, edition)?;
32+
top_mod_content = fmt(&top_mod_content, edition)?;
3333
}
3434
let diff = run_diff(old, new, &top_mod_content)?;
3535
if diff > 0 {
@@ -65,7 +65,7 @@ pub struct ProtoWorkspace {
6565
#[derive(Debug)]
6666
pub struct GenOptions {
6767
pub commit: bool,
68-
pub format: bool,
68+
pub format: Option<String>,
6969
pub prepend_header: Option<String>,
7070
pub toplevel_attribute: Option<String>,
7171
}
@@ -506,7 +506,7 @@ fn path_from_starts_with(root: &str, path: impl AsRef<Path> + Debug) -> Result<P
506506
Ok(pb)
507507
}
508508

509-
fn recurse_fmt(base: impl AsRef<Path>) -> Result<(), String> {
509+
fn recurse_fmt(base: impl AsRef<Path>, edition: &str) -> Result<(), String> {
510510
let path = base.as_ref();
511511
for file in
512512
fs::read_dir(path).map_err(|e| format!("failed to read_dir for path {path:?} \n{e}"))?
@@ -520,7 +520,7 @@ fn recurse_fmt(base: impl AsRef<Path>) -> Result<(), String> {
520520
let out = std::process::Command::new("rustfmt")
521521
.arg(&path)
522522
.arg("--edition")
523-
.arg("2021")
523+
.arg(edition)
524524
.output()
525525
.map_err(|e| format!("Failed to format generated code \n{e}"))?;
526526
if !out.status.success() {
@@ -531,19 +531,19 @@ fn recurse_fmt(base: impl AsRef<Path>) -> Result<(), String> {
531531
));
532532
}
533533
} else if metadata.is_dir() {
534-
recurse_fmt(path)?;
534+
recurse_fmt(path, edition)?;
535535
}
536536
}
537537
Ok(())
538538
}
539539

540-
fn fmt(code: &str) -> Result<String, String> {
540+
fn fmt(code: &str, edition: &str) -> Result<String, String> {
541541
use std::io::Write;
542542
use std::process::Stdio;
543543

544544
let mut child = std::process::Command::new("rustfmt")
545545
.arg("--edition")
546-
.arg("2021")
546+
.arg(edition)
547547
.stdin(Stdio::piped())
548548
.stdout(Stdio::piped())
549549
.spawn()

proto-gen/src/main.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ struct Opts {
2727
#[clap(flatten)]
2828
tonic: TonicOpts,
2929

30-
/// Use `rustfmt` on the code after generation, `rustfmt` needs to be on the path.
31-
#[clap(short, long)]
32-
format: bool,
30+
/// Run rustfmt on the generated code with the specified edition
31+
#[clap(short, long, value_name = "EDITION")]
32+
format: Option<String>,
3333

3434
/// Prepend header indicating tool version in generated source files.
3535
#[clap(short, long, default_value_t = false)]

0 commit comments

Comments
 (0)