@@ -236,18 +236,10 @@ impl Shell {
236
236
..
237
237
} = self . output
238
238
{
239
- let cfg = match color {
240
- Some ( "always" ) => ColorChoice :: Always ,
241
- Some ( "never" ) => ColorChoice :: Never ,
242
-
243
- Some ( "auto" ) | None => ColorChoice :: CargoAuto ,
244
-
245
- Some ( arg) => anyhow:: bail!(
246
- "argument for --color must be auto, always, or \
247
- never, but found `{}`",
248
- arg
249
- ) ,
250
- } ;
239
+ let cfg = color
240
+ . map ( |c| c. parse ( ) )
241
+ . transpose ( ) ?
242
+ . unwrap_or ( ColorChoice :: CargoAuto ) ;
251
243
* color_choice = cfg;
252
244
let stdout_choice = cfg. to_anstream_color_choice ( ) ;
253
245
let stderr_choice = cfg. to_anstream_color_choice ( ) ;
@@ -499,6 +491,25 @@ impl ColorChoice {
499
491
}
500
492
}
501
493
494
+ impl std:: str:: FromStr for ColorChoice {
495
+ type Err = anyhow:: Error ;
496
+ fn from_str ( color : & str ) -> Result < Self , Self :: Err > {
497
+ let cfg = match color {
498
+ "always" => ColorChoice :: Always ,
499
+ "never" => ColorChoice :: Never ,
500
+
501
+ "auto" => ColorChoice :: CargoAuto ,
502
+
503
+ arg => anyhow:: bail!(
504
+ "argument for --color must be auto, always, or \
505
+ never, but found `{}`",
506
+ arg
507
+ ) ,
508
+ } ;
509
+ Ok ( cfg)
510
+ }
511
+ }
512
+
502
513
fn supports_color ( choice : anstream:: ColorChoice ) -> bool {
503
514
match choice {
504
515
anstream:: ColorChoice :: Always
0 commit comments