-
Notifications
You must be signed in to change notification settings - Fork 0
/
help.go
130 lines (103 loc) · 2.37 KB
/
help.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
package cmd
import (
"fmt"
"github.com/ictrobot/aoc-go/internal/solution"
"io"
"os"
"runtime/debug"
"strconv"
"strings"
)
func printHelp(error string) {
w := os.Stdout
if error != "" {
w = os.Stderr
_, _ = fmt.Fprintf(w, "%s\n\n", error)
}
_, _ = fmt.Fprintln(w, `Usage:
aoc
run all solutions
aoc $year
run all solutions for the given year
aoc $year $day
run the solution for the given year & day
aoc $year $day $part
run the solution for the given year, day & part`)
if error != "" {
_, _ = fmt.Fprintln(w, "\nSee --help for more information")
os.Exit(2)
}
_, _ = fmt.Fprintf(w, `
Options:
--example/-e
use the example input, do not use previously downloaded inputs or
attempt to download inputs using a session token (read from the
AOC_TOKEN environment variable, ~/.aoc_token, or stdin)
--timing/-t
print how long it takes to parse the input & solve each part
--parsed/-p
print the parsed input
--pprof
run the specified solutions in a loop for at least %d iterations or
%d seconds (whichever is longer) and write a cpu profile to %s
--help/-h
print help`, pprofMinIterations, pprofSeconds, pprofFilename)
printSolutions(w)
printBuild(w)
os.Exit(0)
}
func printSolutions(w io.Writer) {
years := solution.Years()
if len(years) == 0 {
_, _ = fmt.Fprintln(w, "\nSolutions:\n\t[none]")
return
}
b := strings.Builder{}
b.WriteString("\nSolutions:\n")
for _, year := range years {
b.WriteByte('\t')
b.WriteString(strconv.Itoa(year))
b.WriteString(": ")
days := solution.Days(year)
for i, day := range days {
if i > 0 {
b.WriteString(", ")
}
b.WriteString(strconv.Itoa(day))
}
b.WriteByte('\n')
}
_, _ = fmt.Fprint(w, b.String())
}
func printBuild(w io.Writer) {
info, ok := debug.ReadBuildInfo()
if !ok {
return
}
var revision, time, modified string
for _, s := range info.Settings {
switch s.Key {
case "vcs.revision":
revision = s.Value
case "vcs.time":
time = s.Value
case "vcs.modified":
modified = s.Value
}
}
s := "\n" + info.Path + " "
if revision != "" {
s += "(" + revision
if time != "" {
s += " " + time
}
if modified != "" && modified != "false" {
s += " modified"
}
s += ") "
} else if info.Main.Version != "" && info.Main.Version != "(devel)" {
s += "(" + info.Main.Version + ") "
}
s += info.GoVersion + "\n"
_, _ = fmt.Fprint(w, s)
}