@@ -5,35 +5,35 @@ use std::{
55} ;
66
77#[ derive( Debug ) ]
8- pub enum AocCliError {
8+ pub enum AocCommandError {
99 CommandNotFound ,
1010 CommandNotCallable ,
1111 BadExitStatus ( Output ) ,
1212 IoError ,
1313}
1414
15- impl Display for AocCliError {
15+ impl Display for AocCommandError {
1616 fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
1717 match self {
18- AocCliError :: CommandNotFound => write ! ( f, "aoc-cli is not present in environment." ) ,
19- AocCliError :: CommandNotCallable => write ! ( f, "aoc-cli could not be called." ) ,
20- AocCliError :: BadExitStatus ( _) => {
18+ AocCommandError :: CommandNotFound => write ! ( f, "aoc-cli is not present in environment." ) ,
19+ AocCommandError :: CommandNotCallable => write ! ( f, "aoc-cli could not be called." ) ,
20+ AocCommandError :: BadExitStatus ( _) => {
2121 write ! ( f, "aoc-cli exited with a non-zero status." )
2222 }
23- AocCliError :: IoError => write ! ( f, "could not write output files to file system." ) ,
23+ AocCommandError :: IoError => write ! ( f, "could not write output files to file system." ) ,
2424 }
2525 }
2626}
2727
28- pub fn check ( ) -> Result < ( ) , AocCliError > {
28+ pub fn check ( ) -> Result < ( ) , AocCommandError > {
2929 Command :: new ( "aoc" )
3030 . arg ( "-V" )
3131 . output ( )
32- . map_err ( |_| AocCliError :: CommandNotFound ) ?;
32+ . map_err ( |_| AocCommandError :: CommandNotFound ) ?;
3333 Ok ( ( ) )
3434}
3535
36- pub fn read ( day : u8 ) -> Result < Output , AocCliError > {
36+ pub fn read ( day : u8 ) -> Result < Output , AocCommandError > {
3737 let puzzle_path = get_puzzle_path ( day) ;
3838
3939 let args = build_args (
@@ -49,7 +49,7 @@ pub fn read(day: u8) -> Result<Output, AocCliError> {
4949 call_aoc_cli ( & args)
5050}
5151
52- pub fn download ( day : u8 ) -> Result < Output , AocCliError > {
52+ pub fn download ( day : u8 ) -> Result < Output , AocCommandError > {
5353 let input_path = get_input_path ( day) ;
5454 let puzzle_path = get_puzzle_path ( day) ;
5555
@@ -72,7 +72,7 @@ pub fn download(day: u8) -> Result<Output, AocCliError> {
7272 Ok ( output)
7373}
7474
75- pub fn submit ( day : u8 , part : u8 , result : & str ) -> Result < Output , AocCliError > {
75+ pub fn submit ( day : u8 , part : u8 , result : & str ) -> Result < Output , AocCommandError > {
7676 // workaround: the argument order is inverted for submit.
7777 let mut args = build_args ( "submit" , & [ ] , day) ;
7878 args. push ( part. to_string ( ) ) ;
@@ -81,13 +81,13 @@ pub fn submit(day: u8, part: u8, result: &str) -> Result<Output, AocCliError> {
8181}
8282
8383fn get_input_path ( day : u8 ) -> String {
84- let day_padded = format ! ( "{:02}" , day ) ;
85- format ! ( "data/inputs/{}.txt" , day_padded )
84+ let day_padded = format ! ( "{day :02}" ) ;
85+ format ! ( "data/inputs/{day_padded }.txt" )
8686}
8787
8888fn get_puzzle_path ( day : u8 ) -> String {
89- let day_padded = format ! ( "{:02}" , day ) ;
90- format ! ( "data/puzzles/{}.md" , day_padded )
89+ let day_padded = format ! ( "{day :02}" ) ;
90+ format ! ( "data/puzzles/{day_padded }.md" )
9191}
9292
9393fn get_year ( ) -> Option < u16 > {
@@ -110,18 +110,18 @@ fn build_args(command: &str, args: &[String], day: u8) -> Vec<String> {
110110 cmd_args
111111}
112112
113- fn call_aoc_cli ( args : & [ String ] ) -> Result < Output , AocCliError > {
113+ fn call_aoc_cli ( args : & [ String ] ) -> Result < Output , AocCommandError > {
114114 // println!("Calling >aoc with: {}", args.join(" "));
115115 let output = Command :: new ( "aoc" )
116116 . args ( args)
117117 . stdout ( Stdio :: inherit ( ) )
118118 . stderr ( Stdio :: inherit ( ) )
119119 . output ( )
120- . map_err ( |_| AocCliError :: CommandNotCallable ) ?;
120+ . map_err ( |_| AocCommandError :: CommandNotCallable ) ?;
121121
122122 if output. status . success ( ) {
123123 Ok ( output)
124124 } else {
125- Err ( AocCliError :: BadExitStatus ( output) )
125+ Err ( AocCommandError :: BadExitStatus ( output) )
126126 }
127127}
0 commit comments