/
sleep.go
40 lines (34 loc) · 868 Bytes
/
sleep.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
package root
import (
"fmt"
"github.com/miquido/alertmanager-webhook-forwarder/pkg/conditional_runner"
"github.com/spf13/cobra"
"k8s.io/klog"
"strconv"
"time"
)
var SleepCmd = &cobra.Command{
Use: "sleep",
Short: "Sleep some seconds",
Args: cobra.ExactArgs(1),
Long: `
alertmanager-webhook-forwarder sleep 5
`,
RunE: func(cmd *cobra.Command, args []string) (err error) {
sleepPeriodSeconds, err := strconv.ParseInt(args[0], 10, 64)
if err != nil {
return err
}
if sleepPeriodSeconds < 0 {
return fmt.Errorf("provided argument must be a positive number, %v given", sleepPeriodSeconds)
}
klog.V(7).Infof("sleeping for %d second(s)", sleepPeriodSeconds)
conditional_runner.NotDryRun().Run(func() {
time.Sleep(time.Duration(sleepPeriodSeconds) * time.Second)
})
return nil
},
}
func init() {
RootCmd.AddCommand(SleepCmd)
}