@@ -3,6 +3,8 @@ use clap::{
3
3
error:: { ContextKind , ContextValue } ,
4
4
} ;
5
5
6
+ use crate :: ClapError ;
7
+
6
8
/// Stores the deprecated command name and the new command name to use.
7
9
#[ derive( Clone ) ]
8
10
pub struct DeprecatedCommand {
@@ -25,7 +27,7 @@ pub struct Deprecation;
25
27
26
28
impl Deprecation {
27
29
fn find_deprecated_command (
28
- error : & clap :: error :: Error ,
30
+ error : & ClapError ,
29
31
deprecated_commands : Vec < DeprecatedCommand > ,
30
32
) -> Option < DeprecatedCommand > {
31
33
if let Some ( context_value) = error. get ( ContextKind :: InvalidSubcommand ) {
@@ -40,11 +42,11 @@ impl Deprecation {
40
42
41
43
/// Modify result to add information on deprecated commands.
42
44
pub fn handle_deprecated_commands < A > (
43
- matches_result : Result < A , clap :: error :: Error > ,
45
+ matches_result : Result < A , ClapError > ,
44
46
styles : Styles ,
45
47
deprecated_commands : Vec < DeprecatedCommand > ,
46
- ) -> Result < A , clap :: error :: Error > {
47
- matches_result. map_err ( |mut e : clap :: error :: Error | {
48
+ ) -> Result < A , ClapError > {
49
+ matches_result. map_err ( |mut e : ClapError | {
48
50
if let Some ( deprecated_command) = Self :: find_deprecated_command ( & e, deprecated_commands)
49
51
{
50
52
let message = format ! (
@@ -83,9 +85,9 @@ mod tests {
83
85
84
86
#[ test]
85
87
fn invalid_sub_command_message_for_a_non_deprecated_command_is_not_modified ( ) {
86
- fn build_error ( ) -> Result < MyCommand , clap :: error :: Error > {
87
- let mut e = clap :: error :: Error :: new ( ErrorKind :: InvalidSubcommand )
88
- . with_cmd ( & MyCommand :: command ( ) ) ;
88
+ fn build_error ( ) -> Result < MyCommand , ClapError > {
89
+ let mut e =
90
+ ClapError :: new ( ErrorKind :: InvalidSubcommand ) . with_cmd ( & MyCommand :: command ( ) ) ;
89
91
90
92
e. insert (
91
93
ContextKind :: InvalidSubcommand ,
@@ -109,15 +111,14 @@ mod tests {
109
111
110
112
#[ test]
111
113
fn replace_error_message_on_deprecated_commands_and_show_the_new_command ( ) {
112
- let mut e = clap:: error:: Error :: new ( clap:: error:: ErrorKind :: InvalidSubcommand )
113
- . with_cmd ( & MyCommand :: command ( ) ) ;
114
+ let mut e = ClapError :: new ( ErrorKind :: InvalidSubcommand ) . with_cmd ( & MyCommand :: command ( ) ) ;
114
115
e. insert (
115
116
ContextKind :: InvalidSubcommand ,
116
117
ContextValue :: String ( "old_command" . to_string ( ) ) ,
117
118
) ;
118
119
119
120
let result = Deprecation :: handle_deprecated_commands (
120
- Err ( e) as Result < MyCommand , clap :: error :: Error > ,
121
+ Err ( e) as Result < MyCommand , ClapError > ,
121
122
Styles :: plain ( ) ,
122
123
vec ! [ DeprecatedCommand :: new( "old_command" , "new_command" ) ] ,
123
124
) ;
0 commit comments