feat(cli): allow skipping rustfmt project reformatting when adding a plugin (#10457)

* feat(cli): allow skipping rustfmt project reformatting

* Apply suggestions from code review

* fixes, change file

* fix change file

---------

Co-authored-by: Lucas Fernandes Nogueira <lucas@tauri.app>
This commit is contained in:
Maarten 2024-08-10 22:09:07 +02:00 committed by GitHub
parent 92cac12a92
commit bba1a44191
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 19 additions and 6 deletions

View File

@ -0,0 +1,6 @@
---
"tauri-cli": "patch:enhance"
"@tauri-apps/cli": "patch:enhance"
---
Added `--no-fmt` option to the `add` command to skip formatting the code after applying changes.

View File

@ -86,6 +86,9 @@ pub struct Options {
/// Git branch to use.
#[clap(short, long)]
pub branch: Option<String>,
/// Don't format code with rustfmt
#[clap(long)]
pub no_fmt: bool,
}
pub fn command(options: Options) -> Result<()> {
@ -185,12 +188,15 @@ pub fn command(options: Options) -> Result<()> {
log::info!("Adding plugin to {}", file.display());
std::fs::write(file, out.as_bytes())?;
// run cargo fmt
log::info!("Running `cargo fmt`...");
let _ = Command::new("cargo")
.arg("fmt")
.current_dir(&tauri_dir)
.status();
if !options.no_fmt {
// reformat code with rustfmt
log::info!("Running `cargo fmt`...");
let _ = Command::new("cargo")
.arg("fmt")
.current_dir(&tauri_dir)
.status();
}
return Ok(());
}
}

View File

@ -28,6 +28,7 @@ pub fn run() -> Result<()> {
branch: None,
tag: None,
rev: None,
no_fmt: false,
})
.with_context(|| format!("Could not migrate plugin '{plugin}'"))?;
}