Skip to content

Commit 2b554c3

Browse files
fix(core): revert to clap 3.0 API, allow deprecations, closes #3549 (#3552)
Co-authored-by: chip <chip@chip.sh>
1 parent 0163489 commit 2b554c3

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

.changes/clap-3.0.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"tauri": patch
3+
---
4+
5+
Revert the `clap` usage back to the version 3.0 API.

core/tauri/src/api/cli.rs

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,33 @@ use crate::{
99
PackageInfo,
1010
};
1111

12-
use clap::{Arg, ArgMatches, Command, ErrorKind};
12+
use clap::{Arg, ArgMatches, ErrorKind};
1313
use serde::Serialize;
1414
use serde_json::Value;
1515
use std::collections::HashMap;
1616

1717
#[macro_use]
1818
mod macros;
1919

20+
mod clapfix {
21+
//! Compatibility between `clap` 3.0 and 3.1+ without deprecation errors.
22+
#![allow(deprecated)]
23+
24+
pub type ClapCommand<'help> = clap::App<'help>;
25+
26+
pub trait ErrorExt {
27+
fn kind(&self) -> clap::ErrorKind;
28+
}
29+
30+
impl ErrorExt for clap::Error {
31+
fn kind(&self) -> clap::ErrorKind {
32+
self.kind
33+
}
34+
}
35+
}
36+
37+
use clapfix::{ClapCommand as App, ErrorExt};
38+
2039
/// The resolution of a argument match.
2140
#[derive(Default, Debug, Serialize)]
2241
#[non_exhaustive]
@@ -83,7 +102,7 @@ pub fn get_matches(cli: &CliConfig, package_info: &PackageInfo) -> crate::api::R
83102
let app = get_app(package_info, &package_info.name, Some(&about), cli);
84103
match app.try_get_matches() {
85104
Ok(matches) => Ok(get_matches_internal(cli, &matches)),
86-
Err(e) => match e.kind() {
105+
Err(e) => match ErrorExt::kind(&e) {
87106
ErrorKind::DisplayHelp => {
88107
let mut matches = Matches::default();
89108
let help_text = e.to_string();
@@ -159,8 +178,8 @@ fn get_app<'a>(
159178
command_name: &'a str,
160179
about: Option<&'a String>,
161180
config: &'a CliConfig,
162-
) -> Command<'a> {
163-
let mut app = Command::new(command_name)
181+
) -> App<'a> {
182+
let mut app = App::new(command_name)
164183
.author(package_info.authors)
165184
.version(&*package_info.version);
166185

0 commit comments

Comments
 (0)