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

Co-authored-by: chip <chip@chip.sh>
This commit is contained in:
Lucas Fernandes Nogueira 2022-02-24 11:29:31 -03:00 committed by GitHub
parent 0163489ed6
commit 2b554c38a5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 4 deletions

5
.changes/clap-3.0.md Normal file
View File

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

View File

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