-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
68 lines (56 loc) · 1.93 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
package main
import (
"os"
"github.com/homeport/freeze-calendar-resource/check"
"github.com/homeport/freeze-calendar-resource/get"
"github.com/homeport/freeze-calendar-resource/lint"
"github.com/homeport/freeze-calendar-resource/put"
"github.com/spf13/cobra"
)
func main() {
if err := NewRootCommand().Execute(); err != nil {
os.Exit(1)
}
}
var rootCommand = &cobra.Command{
Use: "freeze-calendar",
Short: "Freeze Calendar Resource",
}
var lintCommand = cobra.Command{
Use: "lint",
Short: "Checks syntax and semantics of a freeze calendar file",
Args: cobra.ExactArgs(1),
RunE: lint.RunE,
}
var checkCommand = cobra.Command{
Use: "check",
Short: "Fetches the latest freeze calendar and emit its version",
RunE: func(cmd *cobra.Command, args []string) error {
return check.Check(cmd.Context(), cmd.InOrStdin(), cmd.OutOrStdout(), cmd.ErrOrStderr())
},
}
var getCommand = cobra.Command{
Use: "get",
Short: "Fetches the latest version of the freeze calendar and, if within a freeze, fails or sleeps.",
Long: `Fetches the latest version of the freeze calendar and
* If FUSE, the resource simply fails.
* If GATE, the resource sleeps while the current date and time are within a freeze window. This is re-tried every INTERVAL.`,
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
return get.Get(cmd.Context(), cmd.InOrStdin(), cmd.OutOrStdout(), cmd.ErrOrStderr(), args[0])
},
}
var putCommand = cobra.Command{
Use: "put",
Short: "no-op",
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
return put.Put(cmd.Context(), cmd.InOrStdin(), cmd.OutOrStdout(), cmd.ErrOrStderr(), args[0])
},
}
func NewRootCommand() *cobra.Command {
lintCommand.PersistentFlags().BoolVarP(&lint.Verbose, "verbose", "V", false, "verbose output")
rootCommand.AddCommand(&lintCommand, &checkCommand, &getCommand, &putCommand)
rootCommand.SilenceUsage = true
return rootCommand
}