Skip to content

Commit

Permalink
fix(core): revert to clap 3.0 API, allow deprecations, closes #3549 (#…
Browse files Browse the repository at this point in the history
…3552)

Co-authored-by: chip <chip@chip.sh>
  • Loading branch information
lucasfernog and chippers committed Feb 24, 2022
1 parent 0163489 commit 2b554c3
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changes/clap-3.0.md
@@ -0,0 +1,5 @@
---
"tauri": patch
---

Revert the `clap` usage back to the version 3.0 API.
27 changes: 23 additions & 4 deletions core/tauri/src/api/cli.rs
Expand Up @@ -9,14 +9,33 @@ 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;

#[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]
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit 2b554c3

Please sign in to comment.