@@ -28,6 +28,12 @@ pub enum MigratePlan<'def> {
28
28
Auto ( AutoMigratePlan < ' def > ) ,
29
29
}
30
30
31
+ #[ derive( Copy , Clone , PartialEq , Eq ) ]
32
+ pub enum PrettyPrintStyle {
33
+ AnsiColor ,
34
+ NoColor ,
35
+ }
36
+
31
37
impl < ' def > MigratePlan < ' def > {
32
38
/// Get the old `ModuleDef` for this migration plan.
33
39
pub fn old_def ( & self ) -> & ' def ModuleDef {
@@ -45,25 +51,25 @@ impl<'def> MigratePlan<'def> {
45
51
}
46
52
}
47
53
48
- pub fn pretty_print ( & self , no_color : bool ) -> anyhow:: Result < String > {
54
+ pub fn pretty_print ( & self , style : PrettyPrintStyle ) -> anyhow:: Result < String > {
55
+ use PrettyPrintStyle :: * ;
56
+
49
57
match self {
50
58
MigratePlan :: Manual ( _) => {
51
59
anyhow:: bail!( "Manual migration plans are not yet supported for pretty printing." )
52
60
}
53
- MigratePlan :: Auto ( plan) => {
54
- if no_color {
61
+
62
+ MigratePlan :: Auto ( plan) => match style {
63
+ NoColor => {
55
64
let mut fmt = plain_formatter:: PlainFormatter :: new ( 1024 ) ;
56
- format_plan ( & mut fmt, plan)
57
- . map_err ( |e| anyhow:: anyhow!( "Failed to format migration plan: {e}" ) )
58
- . map ( |_| fmt. to_string ( ) )
59
- } else {
60
- // Use the ANSI formatter with colors.
65
+ format_plan ( & mut fmt, plan) . map ( |_| fmt. to_string ( ) )
66
+ }
67
+ AnsiColor => {
61
68
let mut fmt = AnsiFormatter :: new ( 1024 , ColorScheme :: default ( ) ) ;
62
- format_plan ( & mut fmt, plan)
63
- . map_err ( |e| anyhow:: anyhow!( "Failed to format migration plan: {e}" ) )
64
- . map ( |_| fmt. to_string ( ) )
69
+ format_plan ( & mut fmt, plan) . map ( |_| fmt. to_string ( ) )
65
70
}
66
71
}
72
+ . map_err ( |e| anyhow:: anyhow!( "Failed to format migration plan: {e}" ) ) ,
67
73
}
68
74
}
69
75
}
@@ -1433,7 +1439,8 @@ mod tests {
1433
1439
1434
1440
insta:: assert_snapshot!(
1435
1441
"empty_to_populated_migration" ,
1436
- plan. pretty_print( false ) . expect( "should pretty print" )
1442
+ plan. pretty_print( PrettyPrintStyle :: AnsiColor )
1443
+ . expect( "should pretty print" )
1437
1444
) ;
1438
1445
}
1439
1446
@@ -1445,7 +1452,8 @@ mod tests {
1445
1452
1446
1453
insta:: assert_snapshot!(
1447
1454
"updated pretty print" ,
1448
- plan. pretty_print( false ) . expect( "should pretty print" )
1455
+ plan. pretty_print( PrettyPrintStyle :: AnsiColor )
1456
+ . expect( "should pretty print" )
1449
1457
) ;
1450
1458
}
1451
1459
@@ -1457,7 +1465,8 @@ mod tests {
1457
1465
1458
1466
insta:: assert_snapshot!(
1459
1467
"updated pretty print no color" ,
1460
- plan. pretty_print( true ) . expect( "should pretty print" )
1468
+ plan. pretty_print( PrettyPrintStyle :: NoColor )
1469
+ . expect( "should pretty print" )
1461
1470
) ;
1462
1471
}
1463
1472
}
0 commit comments