Parcourir la source

fix(core): revert to clap 3.0 API, allow deprecations, closes #3549 (#3552)

Co-authored-by: chip <chip@chip.sh>
Lucas Fernandes Nogueira il y a 3 ans
Parent
commit
2b554c38a5
2 fichiers modifiés avec 28 ajouts et 4 suppressions
  1. 5 0
      .changes/clap-3.0.md
  2. 23 4
      core/tauri/src/api/cli.rs

+ 5 - 0
.changes/clap-3.0.md

@@ -0,0 +1,5 @@
+---
+"tauri": patch
+---
+
+Revert the `clap` usage back to the version 3.0 API.

+ 23 - 4
core/tauri/src/api/cli.rs

@@ -9,7 +9,7 @@ use crate::{
   PackageInfo,
 };
 
-use clap::{Arg, ArgMatches, Command, ErrorKind};
+use clap::{Arg, ArgMatches, ErrorKind};
 use serde::Serialize;
 use serde_json::Value;
 use std::collections::HashMap;
@@ -17,6 +17,25 @@ use std::collections::HashMap;
 #[macro_use]
 mod macros;
 
+mod clapfix {
+  //! Compatibility between `clap` 3.0 and 3.1+ without deprecation errors.
+  #![allow(deprecated)]
+
+  pub type ClapCommand<'help> = clap::App<'help>;
+
+  pub trait ErrorExt {
+    fn kind(&self) -> clap::ErrorKind;
+  }
+
+  impl ErrorExt for clap::Error {
+    fn kind(&self) -> clap::ErrorKind {
+      self.kind
+    }
+  }
+}
+
+use clapfix::{ClapCommand as App, ErrorExt};
+
 /// The resolution of a argument match.
 #[derive(Default, Debug, Serialize)]
 #[non_exhaustive]
@@ -83,7 +102,7 @@ pub fn get_matches(cli: &CliConfig, package_info: &PackageInfo) -> crate::api::R
   let app = get_app(package_info, &package_info.name, Some(&about), cli);
   match app.try_get_matches() {
     Ok(matches) => Ok(get_matches_internal(cli, &matches)),
-    Err(e) => match e.kind() {
+    Err(e) => match ErrorExt::kind(&e) {
       ErrorKind::DisplayHelp => {
         let mut matches = Matches::default();
         let help_text = e.to_string();
@@ -159,8 +178,8 @@ fn get_app<'a>(
   command_name: &'a str,
   about: Option<&'a String>,
   config: &'a CliConfig,
-) -> Command<'a> {
-  let mut app = Command::new(command_name)
+) -> App<'a> {
+  let mut app = App::new(command_name)
     .author(package_info.authors)
     .version(&*package_info.version);