11using System . CommandLine ;
22using System . Text ;
3+ using BooleanExpressionParser . Formatter ;
34using Spectre . Console ;
45
56namespace BooleanExpressionParser ;
@@ -68,14 +69,17 @@ private static void TableHandler(OutputType outputType, string @true, string @fa
6869 var expressions = ParseExpressions ( args ) ;
6970
7071 var tables = new List < string > ( ) ;
71- var formatter = new Formatter
72+
73+ var formatter = GetFormatter ( outputType ) ;
74+
75+ if ( formatter is DisplayFormatter displayFormatter )
7276 {
73- True = @true ,
74- False = @false ,
75- ColourMode = colourMode ,
76- TrueColour = trueColour ,
77- FalseColour = falseColour
78- } ;
77+ displayFormatter . True = @true ;
78+ displayFormatter . False = @false ;
79+ displayFormatter . ColourMode = colourMode ;
80+ displayFormatter . TrueColour = trueColour ;
81+ displayFormatter . FalseColour = falseColour ;
82+ }
7983
8084 foreach ( var expression in expressions )
8185 {
@@ -118,7 +122,7 @@ private static void TableHandler(OutputType outputType, string @true, string @fa
118122 private static void ConvertHandler ( OutputType outputType , string [ ] args )
119123 {
120124 var expressions = ParseExpressions ( args ) ;
121- var formatter = new Formatter ( ) ;
125+ var formatter = GetFormatter ( outputType ) ;
122126
123127 foreach ( var expression in expressions )
124128 {
@@ -135,6 +139,13 @@ private static void ConvertHandler(OutputType outputType, string[] args)
135139
136140 static List < ExpressionWrapper > ParseExpressions ( string [ ] args ) => args . Length == 0 ? QueryExpressions ( ) : args . Select ( arg => new ExpressionWrapper ( arg ) ) . ToList ( ) ;
137141
142+ static IFormatter GetFormatter ( OutputType outputType ) => outputType switch
143+ {
144+ OutputType . Display => new DisplayFormatter ( ) ,
145+ OutputType . Basic => new BasicFormatter ( ) ,
146+ _ => throw new ArgumentOutOfRangeException ( nameof ( outputType ) , outputType , null )
147+ } ;
148+
138149
139150 static List < ExpressionWrapper > QueryExpressions ( )
140151 {
0 commit comments