-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathcli.go
More file actions
45 lines (41 loc) · 729 Bytes
/
Copy pathcli.go
File metadata and controls
45 lines (41 loc) · 729 Bytes
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
package shukujitsu
import (
"fmt"
"io"
"time"
)
// CLIOption represents an option for CLI.
type CLIOption struct {
Quiet bool
Date string
DateFormat string
Writer io.Writer
}
// RunCLI runs shukujitsu CLI.
// return values
// 0 : is Shukujitsu
// 1 : is not Shukujitsu
// 2 : parse error of -d (date)
func RunCLI(opt *CLIOption) int {
var (
now time.Time
err error
)
if opt.Date == "" {
now = time.Now()
} else {
now, err = time.Parse(opt.DateFormat, opt.Date)
if err != nil {
fmt.Fprintln(opt.Writer, err)
return 2
}
}
name, ok := dates[now.Format("2006/1/2")]
if !opt.Quiet {
fmt.Fprintln(opt.Writer, now.Format(opt.DateFormat), name)
}
if !ok {
return 1
}
return 0
}