Browse Source

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>
Maarten 1 year ago
parent
commit
bba1a44191
3 changed files with 19 additions and 6 deletions
  1. 6 0
      .changes/cli-add-no-fmt.md
  2. 12 6
      tooling/cli/src/add.rs
  3. 1 0
      tooling/cli/src/migrate/migrations/v1/mod.rs

+ 6 - 0
.changes/cli-add-no-fmt.md

@@ -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.

+ 12 - 6
tooling/cli/src/add.rs

@@ -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(());
     }
   }

+ 1 - 0
tooling/cli/src/migrate/migrations/v1/mod.rs

@@ -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}'"))?;
   }