-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
46 lines (39 loc) · 853 Bytes
/
main.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
package main
import (
"fmt"
"os"
"github.com/crossedbot/go-markov-image/markov"
)
const (
// Exit codes
ExitCodeFatal = iota + 1
)
func main() {
run()
}
// run is the entry point into the markov-image application
func run() {
if len(os.Args) < 3 {
usage()
}
m := markov.New()
fatal(m.ReadFile(os.Args[1]), "failed to read input file")
fatal(m.WriteFile(os.Args[2]), "failed to write output file")
}
// usage prints the applications usage/help and exits
func usage() {
fmt.Printf(
"usage: %s <input>.png <output>.png"+
" -- generate a new image using Markov chaining\n",
os.Args[0],
)
os.Exit(0)
}
// fatal prints the given message and error, and exits with a fatal code, if the
// given error is not nil.
func fatal(err error, msg string) {
if err != nil {
fmt.Printf("%s: %s\n", msg, err)
os.Exit(ExitCodeFatal)
}
}