Skip to content

Commit 7b5ecb3

Browse files
committed
add --second --minute --hour flag
1 parent a49fd80 commit 7b5ecb3

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

cmd/root.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ import (
1313

1414
var (
1515
version string
16+
17+
flagSecond bool
18+
flagMinute bool
19+
flagHour bool
1620
)
1721

1822
var rootCmd = &cobra.Command{
@@ -32,6 +36,15 @@ var rootCmd = &cobra.Command{
3236
}
3337

3438
base := time.Second
39+
switch {
40+
case flagSecond:
41+
base = time.Second
42+
case flagMinute:
43+
base = time.Minute
44+
case flagHour:
45+
base = time.Hour
46+
}
47+
3548
m := model.New(&model.Config{
3649
Duration: time.Duration(t * float64(base)),
3750
})
@@ -61,4 +74,9 @@ func init() {
6174
}
6275
}
6376
rootCmd.Version = version
77+
78+
rootCmd.Flags().BoolVar(&flagSecond, "second", false, "set the time unit to seconds (default)")
79+
rootCmd.Flags().BoolVar(&flagMinute, "minute", false, "set the time unit to minutes")
80+
rootCmd.Flags().BoolVar(&flagHour, "hour", false, "set the time unit to hours")
81+
rootCmd.MarkFlagsMutuallyExclusive("second", "minute", "hour")
6482
}

0 commit comments

Comments
 (0)