Skip to content

Commit

Permalink
feat(cli): allow skipping rustfmt project reformatting when adding a …
Browse files Browse the repository at this point in the history
…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>
  • Loading branch information
mmvanheusden and lucasfernog authored Aug 10, 2024
1 parent 92cac12 commit bba1a44
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
6 changes: 6 additions & 0 deletions .changes/cli-add-no-fmt.md
Original file line number Diff line number Diff line change
@@ -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.
18 changes: 12 additions & 6 deletions tooling/cli/src/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<()> {
Expand Down Expand Up @@ -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(());
}
}
Expand Down
1 change: 1 addition & 0 deletions tooling/cli/src/migrate/migrations/v1/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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}'"))?;
}
Expand Down

0 comments on commit bba1a44

Please sign in to comment.