1- import { Command } from "https://deno.land/x/cliffy/command/mod.ts" ;
1+ import { Command } from "https://deno.land/x/cliffy@v0.25.4 /command/mod.ts" ;
22import { createDay } from "./create.ts" ;
33import { runAllDays , runDay } from "./run.ts" ;
4+ import { Format } from "./types.d.ts" ;
5+ import { isFormat } from "./utils.ts" ;
46
57try {
68 await new Command ( )
79 . name ( "aoc" )
8- . version ( "<version> " )
10+ . version ( "0.1.1 " )
911 . description ( "Solutions for Advent of Code. https://adventofcode.com/" )
1012 . throwErrors ( )
1113 . command (
1214 "run" ,
1315 new Command ( )
1416 . description ( "Run day solution" )
15- . option ( "-d, --day <day:number>" , "Day to run" )
17+ . option ( "-d, --day <day:number>" , "Day to run" , { required : true } )
1618 . option (
1719 "-p, --part <part:number>" ,
1820 "Part of the day solution to run." ,
19- { default : 1 } ,
21+ { required : true } ,
2022 )
2123 . option (
2224 "-a, --all-parts" ,
2325 "Execute both parts. If present part option will be ignore." ,
26+ { conflicts : [ "part" ] } ,
2427 )
2528 . option ( "-t, --time" , "Show spent time" )
2629 . option (
3740 "Output format." ,
3841 {
3942 default : "plain" ,
40- value ( value : string ) {
41- if ( ! [ "plain" , "json" , "csv" ] . includes ( value ) ) {
43+ value ( value : string ) : Format {
44+ if ( ! isFormat ( value ) ) {
4245 throw new Error (
4346 `Format must be one of plain, json or csv but got: ${ value } ` ,
4447 ) ;
4851 } ,
4952 )
5053 . action ( ( { day, part, allParts, time, sample, format, file } ) =>
51- runDay ( day , file , { part, allParts, time, sample, format } )
54+ runDay (
55+ day ,
56+ file ,
57+ { part, allParts, time, sample, format } ,
58+ )
5259 ) ,
5360 )
5461 . command (
6269 )
6370 . option (
6471 "-a, --all-parts" ,
65- "Execute both parts. If present part option will be ignore." ,
72+ "Execute both parts. If present 'part' option will be ignore." ,
73+ { conflicts : [ "part" ] } ,
6674 )
6775 . option ( "-t, --time" , "Show spent time" )
6876 . option (
@@ -74,13 +82,13 @@ try {
7482 "Output format." ,
7583 {
7684 default : "plain" ,
77- value ( value : string ) {
78- if ( ! [ "plain" , "json" , "csv" ] . includes ( value ) ) {
79- throw new Error (
80- `Format must be one of plain, json or csv but got: ${ value } ` ,
81- ) ;
85+ value ( value : string ) : Format {
86+ if ( isFormat ( value ) ) {
87+ return value ;
8288 }
83- return value ;
89+ throw new Error (
90+ `Format must be one of plain, json or csv but got: ${ value } ` ,
91+ ) ;
8492 } ,
8593 } ,
8694 )
92100 . description ( "Create new day solution folder skeleton" )
93101 . option (
94102 "-d, --day <day:number>" ,
95- "Day of the solution. By default the corresponding next day will be created." ,
103+ "Day of the solution. If omit the corresponding next day will be created." ,
96104 )
97105 . action ( ( { day } ) => createDay ( day ) ) ,
98106 )
0 commit comments