-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmeowify.go
61 lines (48 loc) · 1.04 KB
/
meowify.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
package main
import (
"bufio"
"flag"
"fmt"
"log"
"os"
"github.com/hungneox/meowify/cats"
)
func handle(fileName string, translate bool, cat cats.CatInterface) {
file, err := os.Open(fileName) // just pass the file name
if err != nil {
fmt.Print(err)
}
defer file.Close()
scanner := bufio.NewScanner(file)
for scanner.Scan() {
if scanner.Text() == "" {
continue
}
if translate {
fmt.Println()
fmt.Println(scanner.Text())
}
fmt.Println(cat.MeowifyLine(scanner.Text()))
}
if err := scanner.Err(); err != nil {
log.Fatal(err)
}
}
func main() {
// input := "Roses are red, violets are blue, sugar is sweet, and so are you."
var cat cats.CatInterface
fileName := flag.String("f", "", "Input text file")
translate := flag.Bool("t", false, "Translate line by line")
lang := flag.String("l", "en", "Choose cat language (en|jp)")
flag.Parse()
if *fileName == "" {
flag.PrintDefaults()
os.Exit(1)
}
if *lang == "en" {
cat = cats.Meow{}
} else {
cat = cats.Nyan{}
}
handle(*fileName, *translate, cat)
}