-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmain.go
More file actions
42 lines (34 loc) · 709 Bytes
/
main.go
File metadata and controls
42 lines (34 loc) · 709 Bytes
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
package main
import (
"flag"
"fmt"
"math/rand"
"os"
"time"
)
const (
defaultFileName = "pets.hcl"
)
func main() {
if err := inner(); err != nil {
fmt.Printf("pet-sounds error: %s\n", err.Error())
os.Exit(1)
}
}
func inner() error {
var inputFile string
flag.StringVar(&inputFile, "file", defaultFileName, "the file to read pet configuration from")
flag.StringVar(&inputFile, "f", defaultFileName, "the file to read pet configuration from (shorthand)")
flag.Parse()
// There is a random function for the HCL configuration.
rand.Seed(time.Now().Unix())
pets, err := ReadConfig(inputFile)
if err != nil {
return err
}
for _, p := range pets {
p.Say()
p.Act()
}
return nil
}