@@ -115,19 +115,27 @@ pub fn handle_clap_error_with_exit_code(err: Error, util_name: &str, exit_code:
115
115
ErrorKind :: UnknownArgument => {
116
116
// Force localization initialization - ignore any previous failures
117
117
crate :: locale:: setup_localization_with_common ( util_name) . ok ( ) ;
118
-
118
+
119
119
// UnknownArgument gets special handling for suggestions, but should still show simple help
120
120
if let Some ( invalid_arg) = err. get ( ContextKind :: InvalidArg ) {
121
121
let arg_str = invalid_arg. to_string ( ) ;
122
122
123
123
// Get the uncolored words from common strings with fallbacks
124
124
let error_word = {
125
125
let translated = translate ! ( "common-error" ) ;
126
- if translated == "common-error" { "error" . to_string ( ) } else { translated }
126
+ if translated == "common-error" {
127
+ "error" . to_string ( )
128
+ } else {
129
+ translated
130
+ }
127
131
} ;
128
132
let tip_word = {
129
133
let translated = translate ! ( "common-tip" ) ;
130
- if translated == "common-tip" { "tip" . to_string ( ) } else { translated }
134
+ if translated == "common-tip" {
135
+ "tip" . to_string ( )
136
+ } else {
137
+ translated
138
+ }
131
139
} ;
132
140
133
141
let colored_arg = maybe_colorize ( & arg_str, Color :: Yellow ) ;
@@ -142,15 +150,18 @@ pub fn handle_clap_error_with_exit_code(err: Error, util_name: &str, exit_code:
142
150
"error_word" => colored_error_word. clone( )
143
151
) ;
144
152
if translated. starts_with ( "clap-error-unexpected-argument" ) {
145
- format ! ( "{}: unexpected argument '{}' found" , colored_error_word, colored_arg)
153
+ format ! (
154
+ "{}: unexpected argument '{}' found" ,
155
+ colored_error_word, colored_arg
156
+ )
146
157
} else {
147
158
translated
148
159
}
149
160
} ;
150
161
eprintln ! ( "{error_msg}" ) ;
151
162
eprintln ! ( ) ;
152
163
153
- // Show suggestion if available
164
+ // Show suggestion if available
154
165
let suggestion = err. get ( ContextKind :: SuggestedArg ) ;
155
166
if let Some ( suggested_arg) = suggestion {
156
167
let colored_suggestion =
@@ -162,7 +173,10 @@ pub fn handle_clap_error_with_exit_code(err: Error, util_name: &str, exit_code:
162
173
"suggestion" => colored_suggestion. clone( )
163
174
) ;
164
175
if translated. starts_with ( "clap-error-similar-argument" ) {
165
- format ! ( " {}: a similar argument exists: '{}'" , colored_tip_word, colored_suggestion)
176
+ format ! (
177
+ " {}: a similar argument exists: '{}'" ,
178
+ colored_tip_word, colored_suggestion
179
+ )
166
180
} else {
167
181
format ! ( " {}" , translated)
168
182
}
@@ -178,7 +192,11 @@ pub fn handle_clap_error_with_exit_code(err: Error, util_name: &str, exit_code:
178
192
let formatted_usage = crate :: format_usage ( & usage_text) ;
179
193
let usage_label = {
180
194
let translated = translate ! ( "common-usage" ) ;
181
- if translated == "common-usage" { "Usage" . to_string ( ) } else { translated }
195
+ if translated == "common-usage" {
196
+ "Usage" . to_string ( )
197
+ } else {
198
+ translated
199
+ }
182
200
} ;
183
201
eprintln ! ( "{}: {}" , usage_label, formatted_usage) ;
184
202
eprintln ! ( ) ;
@@ -190,7 +208,11 @@ pub fn handle_clap_error_with_exit_code(err: Error, util_name: &str, exit_code:
190
208
// Generic fallback case
191
209
let error_word = {
192
210
let translated = translate ! ( "common-error" ) ;
193
- if translated == "common-error" { "error" . to_string ( ) } else { translated }
211
+ if translated == "common-error" {
212
+ "error" . to_string ( )
213
+ } else {
214
+ translated
215
+ }
194
216
} ;
195
217
let colored_error_word = maybe_colorize ( & error_word, Color :: Red ) ;
196
218
eprintln ! ( "{colored_error_word}: unexpected argument" ) ;
0 commit comments