1- use clap:: { Parser , ValueEnum } ;
1+ use clap:: Parser ;
22use std:: fs:: File ;
33use std:: io;
44use std:: io:: Write ;
5- use std:: path:: PathBuf ;
65mod coef;
76mod downset;
87mod flow;
@@ -15,85 +14,24 @@ mod semigroup;
1514mod solution;
1615mod solver;
1716mod strategy;
18- use log:: LevelFilter ;
17+ use log:: info;
18+ mod logging;
19+ mod cli;
1920
20- #[ derive( Debug , Copy , Clone , PartialEq , Eq , PartialOrd , Ord , ValueEnum ) ]
21- enum OutputFormat {
22- Plain ,
23- Tex ,
24- Csv ,
25- }
26-
27- #[ derive( clap:: Parser , Debug ) ]
28- #[ command( version, about, long_about = None ) ]
29- struct Args {
30- #[ arg( value_name = "AUTOMATON_FILE" , help = "path to the input" ) ]
31- filename : String ,
32-
33- #[ arg(
34- short = 'f' ,
35- long = "from" ,
36- value_enum,
37- default_value = "tikz" ,
38- help = "The input format"
39- ) ]
40- input_format : nfa:: InputFormat ,
41-
42- #[ arg(
43- value_enum,
44- short = 't' ,
45- long = "to" ,
46- default_value = "plain" ,
47- help = "The output format"
48- ) ]
49- output_format : OutputFormat ,
50-
51- /// path to write the strategy
52- #[ arg(
53- short = 'o' ,
54- long = "output" ,
55- value_name = "OUTPUT_FILE" ,
56- help = "where to write the strategy; defaults to stdout."
57- ) ]
58- output_path : Option < PathBuf > ,
59-
60- #[ arg(
61- short,
62- long,
63- value_enum,
64- default_value = "input" ,
65- help = format!( "The state reordering type: preserves input order, sorts alphabetically or topologically." )
66- ) ]
67- state_ordering : nfa:: StateOrdering ,
68-
69- #[ arg(
70- long,
71- value_enum,
72- default_value = "strategy" ,
73- help = format!( "The solver output. Either yes/no and a winning strategy (the faster). Or the full maximal winning strategy." )
74- ) ]
75- solver_output : solver:: SolverOutput ,
76- }
7721
7822fn main ( ) {
79- #[ cfg( debug_assertions) ]
80- env_logger:: Builder :: new ( )
81- . filter_level ( LevelFilter :: Debug )
82- . init ( ) ;
83-
84- #[ cfg( not( debug_assertions) ) ]
85- env_logger:: Builder :: new ( )
86- . filter_level ( LevelFilter :: Info )
87- . init ( ) ;
8823
8924 // parse CLI arguments
90- let args = Args :: parse ( ) ;
25+ let args = cli:: Args :: parse ( ) ;
26+
27+ // set up logging
28+ logging:: setup_logger ( args. verbosity , args. log_output ) ;
9129
9230 // parse the input file
9331 let nfa = nfa:: Nfa :: load_from_file ( & args. filename , & args. input_format , & args. state_ordering ) ;
9432
9533 // print the input automaton
96- println ! ( "{}" , nfa) ;
34+ info ! ( "{}" , nfa) ;
9735
9836 // compute the solution
9937 let solution = solver:: solve ( & nfa, & args. solver_output ) ;
@@ -135,20 +73,20 @@ fn main() {
13573
13674 // prepare output string
13775 let output = match args. output_format {
138- OutputFormat :: Tex => {
76+ cli :: OutputFormat :: Tex => {
13977 let is_tikz = args. input_format == nfa:: InputFormat :: Tikz ;
14078 let latex_content =
14179 solution. as_latex ( if is_tikz { Some ( & args. filename ) } else { None } ) ;
14280 latex_content. to_string ( )
14381 }
144- OutputFormat :: Plain => {
82+ cli :: OutputFormat :: Plain => {
14583 format ! (
14684 "States: {}\n {}" ,
14785 nfa. states_str( ) ,
14886 solution. winning_strategy
14987 )
15088 }
151- OutputFormat :: Csv => {
89+ cli :: OutputFormat :: Csv => {
15290 format ! (
15391 "Σ, {}\n {}\n " ,
15492 nfa. states( ) . join( "," ) ,
0 commit comments