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;
@@ -17,86 +16,13 @@ mod solver;
1716mod strategy;
1817use log:: info;
1918mod logging;
19+ mod cli;
2020
2121
22- #[ derive( Debug , Copy , Clone , PartialEq , Eq , PartialOrd , Ord , ValueEnum ) ]
23- enum OutputFormat {
24- Plain ,
25- Tex ,
26- Csv ,
27- }
28-
29- #[ derive( clap:: Parser , Debug ) ]
30- #[ command( version, about, long_about = None ) ]
31- struct Args {
32- #[ arg( value_name = "AUTOMATON_FILE" , help = "path to the input" ) ]
33- filename : String ,
34-
35- #[ arg(
36- short = 'f' ,
37- long = "from" ,
38- value_enum,
39- default_value = "tikz" ,
40- help = "The input format"
41- ) ]
42- input_format : nfa:: InputFormat ,
43-
44- #[ arg(
45- short = 'v' ,
46- long = "verbose" ,
47- action = clap:: ArgAction :: Count ,
48- help = "Increase verbosity level (use multiple times for more verbose output)"
49- ) ]
50- verbosity : u8 ,
51-
52- #[ arg(
53- long,
54- short = 'l' ,
55- value_name = "LOG_FILE" ,
56- help = "Optional path to the log file. Defaults to stdout if not specified."
57- ) ]
58- log_output : Option < PathBuf > ,
59-
60- #[ arg(
61- value_enum,
62- short = 't' ,
63- long = "to" ,
64- default_value = "plain" ,
65- help = "The output format"
66- ) ]
67- output_format : OutputFormat ,
68-
69- /// path to write the strategy
70- #[ arg(
71- short = 'o' ,
72- long = "output" ,
73- value_name = "OUTPUT_FILE" ,
74- help = "where to write the strategy; defaults to stdout."
75- ) ]
76- output_path : Option < PathBuf > ,
77-
78- #[ arg(
79- short,
80- long,
81- value_enum,
82- default_value = "input" ,
83- help = format!( "The state reordering type: preserves input order, sorts alphabetically or topologically." )
84- ) ]
85- state_ordering : nfa:: StateOrdering ,
86-
87- #[ arg(
88- long,
89- value_enum,
90- default_value = "strategy" ,
91- help = format!( "The solver output. Either yes/no and a winning strategy (the faster). Or the full maximal winning strategy." )
92- ) ]
93- solver_output : solver:: SolverOutput ,
94- }
95-
9622fn main ( ) {
9723
9824 // parse CLI arguments
99- let args = Args :: parse ( ) ;
25+ let args = cli :: Args :: parse ( ) ;
10026
10127 // set up logging
10228 logging:: setup_logger ( args. verbosity , args. log_output ) ;
@@ -147,20 +73,20 @@ fn main() {
14773
14874 // prepare output string
14975 let output = match args. output_format {
150- OutputFormat :: Tex => {
76+ cli :: OutputFormat :: Tex => {
15177 let is_tikz = args. input_format == nfa:: InputFormat :: Tikz ;
15278 let latex_content =
15379 solution. as_latex ( if is_tikz { Some ( & args. filename ) } else { None } ) ;
15480 latex_content. to_string ( )
15581 }
156- OutputFormat :: Plain => {
82+ cli :: OutputFormat :: Plain => {
15783 format ! (
15884 "States: {}\n {}" ,
15985 nfa. states_str( ) ,
16086 solution. winning_strategy
16187 )
16288 }
163- OutputFormat :: Csv => {
89+ cli :: OutputFormat :: Csv => {
16490 format ! (
16591 "Σ, {}\n {}\n " ,
16692 nfa. states( ) . join( "," ) ,
0 commit comments