@@ -9,14 +9,33 @@ use crate::{
99 PackageInfo ,
1010} ;
1111
12- use clap:: { Arg , ArgMatches , Command , ErrorKind } ;
12+ use clap:: { Arg , ArgMatches , ErrorKind } ;
1313use serde:: Serialize ;
1414use serde_json:: Value ;
1515use std:: collections:: HashMap ;
1616
1717#[ macro_use]
1818mod 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