@@ -13,6 +13,9 @@ struct AdventOfCode: AsyncParsableCommand {
1313 @Flag ( help: " Benchmark the time taken by the solution " )
1414 var benchmark : Bool = false
1515
16+ @Flag ( help: " Run all the days available " )
17+ var all : Bool = false
18+
1619 /// The selected day, or the latest day if no selection is provided.
1720 var selectedChallenge : any AdventDay {
1821 get throws {
@@ -33,36 +36,46 @@ struct AdventOfCode: AsyncParsableCommand {
3336 allChallenges. max ( by: { $0. day < $1. day } ) !
3437 }
3538
36- func run( part: ( ) async throws -> Any , named: String ) async -> Duration {
37- var result : Result < Any , Error > = . success ( " <unsolved> " )
39+ func run< T > ( part: ( ) async throws -> T , named: String ) async -> Duration {
40+ var result : Result < T , Error > ?
3841 let timing = await ContinuousClock ( ) . measure {
3942 do {
4043 result = . success( try await part ( ) )
4144 } catch {
4245 result = . failure( error)
4346 }
4447 }
45- switch result {
48+ switch result! {
4649 case . success( let success) :
4750 print ( " \( named) : \( success) " )
51+ case . failure( let failure as PartUnimplemented ) :
52+ print ( " Day \( failure. day) part \( failure. part) unimplemented " )
4853 case . failure( let failure) :
4954 print ( " \( named) : Failed with error: \( failure) " )
5055 }
5156 return timing
5257 }
5358
5459 func run( ) async throws {
55- let challenge = try selectedChallenge
56- print ( " Executing Advent of Code challenge \( challenge. day) ... " )
60+ let challenges =
61+ if all {
62+ allChallenges
63+ } else {
64+ try [ selectedChallenge]
65+ }
5766
58- let timing1 = await run ( part : challenge. part1 , named : " Part 1 " )
59- let timing2 = await run ( part : challenge . part2 , named : " Part 2 " )
67+ for challenge in challenges {
68+ print ( " Executing Advent of Code challenge \( challenge . day ) ... " )
6069
61- if benchmark {
62- print ( " Part 1 took \( timing1) , part 2 took \( timing2) . " )
63- #if DEBUG
64- print ( " Looks like you're benchmarking debug code. Try swift run -c release " )
65- #endif
70+ let timing1 = await run ( part: challenge. part1, named: " Part 1 " )
71+ let timing2 = await run ( part: challenge. part2, named: " Part 2 " )
72+
73+ if benchmark {
74+ print ( " Part 1 took \( timing1) , part 2 took \( timing2) . " )
75+ #if DEBUG
76+ print ( " Looks like you're benchmarking debug code. Try swift run -c release " )
77+ #endif
78+ }
6679 }
6780 }
6881}
0 commit comments