generated from moul/golang-repo-template
-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.go
46 lines (42 loc) · 736 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"
"io/ioutil"
"log"
"math/rand"
"os"
"strings"
cli "gopkg.in/urfave/cli.v2"
"moul.io/guilhunize/guilhunize"
"moul.io/srand"
)
func main() {
app := cli.App{
Action: run,
Flags: []cli.Flag{
&cli.BoolFlag{Name: "quote"},
},
}
if err := app.Run(os.Args); err != nil {
log.Printf("error: %v\n", err)
os.Exit(1)
}
}
func run(c *cli.Context) error {
if c.Bool("quote") {
rand.Seed(srand.Fast())
fmt.Println(guilhunize.Quote())
return nil
}
message := strings.Join(c.Args().Slice(), " ")
if message == "" {
in, err := ioutil.ReadAll(os.Stdin)
if err != nil {
return err
}
message = string(in)
}
out := guilhunize.Guilhunize(message)
fmt.Println(out)
return nil
}