-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup_templates.go
64 lines (52 loc) · 1.16 KB
/
setup_templates.go
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
62
63
64
package main
import (
"flag"
"fmt"
"html/template"
"os"
"time"
)
const mainFile = `package main
import (
"fmt"
"github.com/A-UNDERSCORE-D/adventofcode/util"
)
func main() {
input := util.ReadLines("{{.Year}}/{{printf "%02d" .Day}}/input.txt")
fmt.Println("Part 1:", part1(input))
fmt.Println("Part 2:", part2(input))
}
func part1(input []string) string {
return "stuff"
}
func part2(input []string) string {
return "stuff2"
}
`
func main() {
var day, year int
flag.IntVar(&day, "day", -1, "The day to create the template for")
flag.IntVar(&year, "year", -1, "The year to create the template for")
flag.Parse()
if day == -1 {
day = time.Now().Day()
fmt.Printf("assuming day is %02d\n", day)
}
if year == -1 {
year = time.Now().Year()
fmt.Printf("assuming year is %02d\n", year)
}
if err := os.MkdirAll(fmt.Sprintf("./%d/%02d", year, day), 0o755); err != nil {
panic(err)
}
t := template.Must(template.New("f").Parse(mainFile))
f, err := os.OpenFile(fmt.Sprintf("./%d/%02d/solution.go", year, day), os.O_CREATE|os.O_WRONLY, 0o644)
if err != nil {
panic(err)
}
defer f.Close()
t.Execute(f, struct {
Day int
Year int
}{day, year})
}