-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpuzzle.go
47 lines (39 loc) · 807 Bytes
/
puzzle.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
package adventofcode
import (
"context"
"flag"
"github.com/google/subcommands"
)
type Puzzle struct {
name string
path string
handler func(string) error
}
func NewPuzzle(n string, f func(string) error) *Puzzle {
return &Puzzle{
name: n,
handler: f,
}
}
func (p *Puzzle) Name() string {
return p.name
}
func (*Puzzle) Synopsis() string {
return ""
}
func (*Puzzle) Usage() string {
return ""
}
func (p *Puzzle) SetFlags(f *flag.FlagSet) {
f.StringVar(&p.path, "input", "", "The puzzle input")
}
func (p *Puzzle) Execute(ctx context.Context, f *flag.FlagSet, args ...interface{}) subcommands.ExitStatus {
if p.path == "" {
return subcommands.ExitUsageError
}
err := p.handler(p.path)
if err != nil {
return subcommands.ExitFailure
}
return subcommands.ExitSuccess
}