@@ -13,6 +13,41 @@ pub enum AocCommandError {
13
13
BadExitStatus ( Output ) ,
14
14
}
15
15
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
+
16
51
impl Display for AocCommandError {
17
52
fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
18
53
match self {
@@ -49,26 +84,24 @@ pub fn read(day: Day) -> Result<Output, AocCommandError> {
49
84
call_aoc_cli ( & args)
50
85
}
51
86
52
- pub fn download ( day : Day ) -> Result < Output , AocCommandError > {
87
+ pub fn download ( day : Day , download_variants : DownloadMode ) -> Result < Output , AocCommandError > {
53
88
let input_path = get_input_path ( day) ;
54
89
let puzzle_path = get_puzzle_path ( day) ;
55
90
56
- let args = build_args (
91
+ let args = & build_args (
57
92
"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) [ ..] ,
65
94
day,
66
95
) ;
67
96
68
97
let output = call_aoc_cli ( & args) ?;
69
98
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
+ }
72
105
Ok ( output)
73
106
}
74
107
0 commit comments