@@ -49,7 +49,7 @@ enum SubCommands {
49
49
}
50
50
51
51
/// Runs the benchmark for the last day (or a given day)
52
- #[ derive( Parser , Debug ) ]
52
+ #[ derive( Parser , Debug , Clone ) ]
53
53
pub struct Bench {
54
54
/// Specifies the day. Defaults to last implemented.
55
55
#[ clap( short, long) ]
@@ -76,14 +76,25 @@ pub struct Bench {
76
76
profile : bool ,
77
77
}
78
78
79
+ impl Bench {
80
+ /// Cascade --day/--part/--input from the root command to the bench command
81
+ fn cascade ( & self , cli : & Cli ) -> Self {
82
+ let mut bench = ( * self ) . clone ( ) ;
83
+ bench. day = self . day . or ( cli. day ) ;
84
+ bench. part = self . part . or ( cli. part ) ;
85
+ bench. input = bench. input . or_else ( || cli. input . clone ( ) ) ;
86
+ bench
87
+ }
88
+ }
89
+
79
90
/// Sets the session cookie
80
91
#[ derive( Parser , Debug ) ]
81
92
pub struct Credentials {
82
93
set : Option < String > ,
83
94
}
84
95
85
96
/// Downloads the input for today (or a given day)
86
- #[ derive( Parser , Debug ) ]
97
+ #[ derive( Parser , Debug , Clone ) ]
87
98
pub struct Input {
88
99
/// Specifies the day. Defaults to today's date.
89
100
#[ clap( short, long) ]
@@ -102,20 +113,29 @@ pub struct Input {
102
113
generate : bool ,
103
114
}
104
115
116
+ impl Input {
117
+ /// Cascade --day from the root command to the bench command
118
+ fn cascade ( & self , cli : & Cli ) -> Self {
119
+ let mut input = ( * self ) . clone ( ) ;
120
+ input. day = self . day . or ( cli. day ) ;
121
+ input
122
+ }
123
+ }
124
+
105
125
fn main ( ) {
106
126
let cli = Cli :: parse_from ( args_without_aoc ( ) ) ;
107
127
108
- let Some ( subcommand) = cli. subcmd else {
128
+ let Some ( ref subcommand) = cli. subcmd else {
109
129
return execute_default ( & cli) . unwrap ( ) ;
110
130
} ;
111
131
112
132
match subcommand {
113
- SubCommands :: Bench ( arg) => execute_bench ( & arg) ,
133
+ SubCommands :: Bench ( arg) => execute_bench ( & arg. cascade ( & cli ) ) ,
114
134
SubCommands :: Credentials ( arg) => {
115
135
execute_credentials ( & arg) ;
116
136
Ok ( ( ) )
117
137
}
118
- SubCommands :: Input ( arg) => execute_input ( & arg) ,
138
+ SubCommands :: Input ( arg) => execute_input ( & arg. cascade ( & cli ) ) ,
119
139
}
120
140
. unwrap ( )
121
141
}
0 commit comments