-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemplate.main.kts
executable file
·61 lines (42 loc) · 1.3 KB
/
template.main.kts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env kotlin
import java.io.File
fun createDay(day: Int, dryRun: Boolean = true) {
val paddedDay = "%02d".format(day)
val template = """
package solutions
import models.InputProvider
context (InputProvider)
class Day$paddedDay : Day($day, 2022, "") {
override fun part1(): Int {
TODO()
}
override fun part2(): Int {
TODO()
}
}
fun main() {
test<Day$paddedDay>(null, null)
solve<Day$paddedDay>()
}
""".trimIndent()
val solutionFile = File("src/main/kotlin/solutions/Day$paddedDay.kt")
val testInputFile = File("src/main/resources/day$paddedDay.example.txt")
val inputFile = File("src/main/resources/day$paddedDay.txt")
val newFiles = listOf(solutionFile, testInputFile, inputFile).filterNot(File::exists)
if (dryRun && newFiles.isNotEmpty()) {
println("would create new files:")
newFiles.forEach { println("- $it") }
return
}
newFiles.forEach(File::createNewFile)
if (solutionFile.readText().isEmpty()) {
solutionFile.writeText(template)
}
}
main(*args)
fun main(vararg args: String) {
require(args.isNotEmpty()) { "version argument required" }
val dayArg = args.first().toInt()
require(dayArg in 1..24) { "day should be between 1 and 24" }
createDay(dayArg, dryRun = false)
}