-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
83 lines (64 loc) · 1.43 KB
/
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package main
import (
"flag"
"fmt"
"io"
"os"
)
func main() {
cmd := flag.NewFlagSet("options", flag.ContinueOnError)
filePath := cmd.String("file", "", "Path to file containing CSV list")
leftVoice := cmd.String("left", "Thomas", "Path to file containing CSV list")
rightVoice := cmd.String("right", "Alex", "Path to file containing CSV list")
reverse := cmd.Bool("reverse", false, "Reverse column order")
if err := cmd.Parse(os.Args[1:]); err != nil {
if err == flag.ErrHelp {
return
}
panic(err)
}
reader, err := makeReader(*filePath)
if err != nil {
fmt.Println(err.Error())
cmd.PrintDefaults()
return
}
prompt := MakePrompt()
for {
leftVal, rightVal, err := reader.ReadLine()
if err == io.EOF {
break
}
if err != nil {
fmt.Println(err.Error())
continue
}
if *reverse {
prompt.Speak(rightVal, *rightVoice)
prompt.Speak(leftVal, *leftVoice)
} else {
prompt.Speak(leftVal, *leftVoice)
prompt.Speak(rightVal, *rightVoice)
}
fmt.Println()
}
}
func makeReader(filePath string) (*Reader, error) {
var reader *Reader
var err error
if filePath != "" {
reader, err = FileReader(filePath)
} else if pipedStdin() {
reader = StdinReader()
} else {
err = fmt.Errorf("Missing input file path")
}
return reader, err
}
func pipedStdin() bool {
info, err := os.Stdin.Stat()
if err != nil {
panic(err.Error)
}
return (info.Mode() & os.ModeCharDevice) != os.ModeCharDevice
}