-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
90 lines (69 loc) · 1.51 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
84
85
86
87
88
89
90
package main
import (
"fmt"
"os"
"time"
"strconv"
"github.com/geremachek/escape"
flag "github.com/spf13/pflag"
fu "plain/funcs"
)
const help = `Usage: plain [OPTION]...
A simple plain english clock
--help, -h: Display this information
--us, -u: Use the U.S. standard AM/PM time
--spaced, -s: Put spacing around the text
--bold, -b: Use bold text`
var (
hour int
xm string
esc string = ""
esce string = ""
)
func main() {
t := time.Now()
hour = t.Hour()
if len(os.Args) == 1 {
convmin, err := fu.ConvertMinute(t.Minute())
if err != nil {
panic(err)
}
convhour, err := fu.ConvertHour(hour)
if err != nil {
panic(err)
}
fmt.Println(convhour + " " + convmin)
} else if os.Args[1] == "-h" || os.Args[1] == "--help" {
fmt.Println(help)
} else {
us := flag.BoolP("us", "u", false, "Use the U.S. standard AM/PM time")
space := flag.BoolP("spaced", "s", false, "Put spacing around the text")
bold := flag.BoolP("bold", "b", false, "Use bold text")
flag.Parse()
if *us {
i, err := strconv.Atoi(t.Format("3"))
if err != nil {
panic(err)
}
hour = i
xm = t.Format(" PM")
}
if *bold {
esc = escape.Vint(1)
esce = escape.Vint(0)
}
convmin, err := fu.ConvertMinute(t.Minute())
if err != nil {
panic(err)
}
convhour, err := fu.ConvertHour(hour)
if err != nil {
panic(err)
}
if *space {
fmt.Print("\n " + esc + convhour + " " + convmin + xm + esce + "\n\n")
} else {
fmt.Println(esc + convhour + " " + convmin + xm + esce)
}
}
}