@@ -2,10 +2,10 @@ pub mod input;
22
33use std:: cmp:: min;
44use std:: iter;
5+ use std:: path:: PathBuf ;
56use std:: time:: Duration ;
67
78pub use clap:: Clap ;
8- pub use colored;
99use colored:: * ;
1010
1111const DISPLAY_WIDTH : usize = 40 ;
@@ -41,11 +41,15 @@ pub fn print_with_duration(line: &str, output: Option<&str>, duration: Duration)
4141) ]
4242pub struct Opt {
4343 /// Read input from stdin instead of downloading it
44- #[ clap( short, long) ]
44+ #[ clap( short = 'i' , long, conflicts_with = "file" ) ]
4545 pub stdin : bool ,
4646
47+ /// Read input from file instead of downloading it
48+ #[ clap( short, long, conflicts_with = "stdin" ) ]
49+ pub file : Option < PathBuf > ,
50+
4751 /// Days to execute. By default all implemented days will run.
48- #[ clap( short, long) ]
52+ #[ clap( name = "day num" , short, long = "day" ) ]
4953 pub days : Vec < String > ,
5054}
5155
@@ -56,8 +60,9 @@ macro_rules! main {
5660 $( $day: ident $( : $generator: ident ) ? => $( $solution: ident ) ,+ ) ;+
5761 $( ; ) ?
5862 ) => {
59- use std:: time :: Instant ;
63+ use std:: fs :: read_to_string ;
6064 use std:: io:: Read ;
65+ use std:: time:: Instant ;
6166
6267 use $crate:: Clap ;
6368
@@ -69,6 +74,27 @@ macro_rules! main {
6974
7075 if opt. days. is_empty( ) {
7176 opt. days = DAYS . iter( ) . map( |s| s[ 3 ..] . to_string( ) ) . collect( ) ;
77+ } else {
78+ let ignored_days: Vec <_> = opt. days
79+ . iter( )
80+ . filter( |day| !DAYS . contains( & format!( "day{}" , day) . as_str( ) ) )
81+ . map( String :: as_str)
82+ . collect( ) ;
83+
84+ if !ignored_days. is_empty( ) {
85+ eprintln!( r"/!\ Ignoring unimplemented days: {}" , ignored_days. join( ", " ) ) ;
86+ }
87+
88+ opt. days = opt. days
89+ . into_iter( )
90+ . filter( |day| DAYS . contains( & format!( "day{}" , day) . as_str( ) ) )
91+ . collect( ) ;
92+ }
93+
94+ if opt. days. len( ) > 1 && ( opt. stdin || opt. file. is_some( ) ) {
95+ eprintln!( r"/!\ You are using a personalized output over several days which can" ) ;
96+ eprintln!( r" be missleading. If you only intend to run solutions for a" ) ;
97+ eprintln!( r" specific day, you can specify it by using the `-d DAY_NUM` flag." ) ;
7298 }
7399
74100 for ( i, day) in opt. days. iter( ) . enumerate( ) {
@@ -94,6 +120,9 @@ macro_rules! main {
94120 std:: io:: stdin( ) . read_to_string( & mut data)
95121 . expect( "failed to read from stdin" ) ;
96122 data
123+ } else if let Some ( path) = opt. file. as_ref( ) {
124+ read_to_string( path)
125+ . expect( "failed to read specified file" )
97126 } else {
98127 $crate:: input:: get_input( YEAR , day) . expect( "could not fetch input" )
99128 }
0 commit comments