@@ -13,6 +13,41 @@ pub enum AocCommandError {
1313 BadExitStatus ( Output ) ,
1414}
1515
16+ pub enum DownloadMode {
17+ InputOnly ,
18+ PuzzleOnly ,
19+ InputAndPuzzle ,
20+ }
21+
22+ impl DownloadMode {
23+ fn modify_args ( & self , input_path : & str , puzzle_path : & str ) -> Vec < String > {
24+ let mut args = vec ! [ "--overwrite" . into( ) ] ;
25+ match self {
26+ DownloadMode :: InputOnly => {
27+ args. extend ( [ "--input-only" , "--input-file" , input_path] . iter ( ) . map ( |s| s. to_string ( ) ) ) ;
28+ }
29+ DownloadMode :: PuzzleOnly => {
30+ args. extend ( [ "--puzzle-only" , "--puzzle-file" , puzzle_path] . iter ( ) . map ( |s| s. to_string ( ) ) ) ;
31+ }
32+ DownloadMode :: InputAndPuzzle => {
33+ args. extend ( [
34+ "--input-file" , input_path,
35+ "--puzzle-file" , puzzle_path
36+ ] . iter ( ) . map ( |s| s. to_string ( ) ) ) ;
37+ }
38+ }
39+ args
40+ }
41+
42+ fn downloads_input ( & self ) -> bool {
43+ matches ! ( self , DownloadMode :: InputOnly | DownloadMode :: InputAndPuzzle )
44+ }
45+
46+ fn downloads_puzzle ( & self ) -> bool {
47+ matches ! ( self , DownloadMode :: PuzzleOnly | DownloadMode :: InputAndPuzzle )
48+ }
49+ }
50+
1651impl Display for AocCommandError {
1752 fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
1853 match self {
@@ -49,26 +84,24 @@ pub fn read(day: Day) -> Result<Output, AocCommandError> {
4984 call_aoc_cli ( & args)
5085}
5186
52- pub fn download ( day : Day ) -> Result < Output , AocCommandError > {
87+ pub fn download ( day : Day , download_variants : DownloadMode ) -> Result < Output , AocCommandError > {
5388 let input_path = get_input_path ( day) ;
5489 let puzzle_path = get_puzzle_path ( day) ;
5590
56- let args = build_args (
91+ let args = & build_args (
5792 "download" ,
58- & [
59- "--overwrite" . into ( ) ,
60- "--input-file" . into ( ) ,
61- input_path. to_string ( ) ,
62- "--puzzle-file" . into ( ) ,
63- puzzle_path. to_string ( ) ,
64- ] ,
93+ & download_variants. modify_args ( & input_path, & puzzle_path) [ ..] ,
6594 day,
6695 ) ;
6796
6897 let output = call_aoc_cli ( & args) ?;
6998 println ! ( "---" ) ;
70- println ! ( "🎄 Successfully wrote input to \" {}\" ." , & input_path) ;
71- println ! ( "🎄 Successfully wrote puzzle to \" {}\" ." , & puzzle_path) ;
99+ if download_variants. downloads_input ( ) {
100+ println ! ( "🎄 Successfully wrote input to \" {}\" ." , & input_path) ;
101+ }
102+ if download_variants. downloads_puzzle ( ) {
103+ println ! ( "🎄 Successfully wrote puzzle to \" {}\" ." , & puzzle_path) ;
104+ }
72105 Ok ( output)
73106}
74107
0 commit comments