-
Notifications
You must be signed in to change notification settings - Fork 2
/
Scaler.go
56 lines (44 loc) · 1013 Bytes
/
Scaler.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
package cmd
import (
"io"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/stakater/Scaler/internal/pkg/cmd/common"
"github.com/stakater/Scaler/internal/pkg/tasks"
)
//NewScalerCommand to run Scaler
func NewScalerCommand(in io.Reader, out, errOut io.Writer) *cobra.Command {
scalerOptions := &common.ScalerOptions{
Options: common.Options{
Out: out,
Err: errOut,
},
}
cmd := &cobra.Command{
Use: "Scaler",
Short: "A tool which updates Auto scaling groups",
RunE: func(cmd *cobra.Command, args []string) error {
scalerOptions.Cmd = cmd
scalerOptions.Args = args
return Run(scalerOptions)
},
}
scalerOptions.AddFlags(cmd)
return cmd
}
//Run - Executes the action of command
func Run(scalerOptions *common.ScalerOptions) error {
err := scalerOptions.ValidateArgs()
if err != nil {
return err
}
task, err := tasks.NewTask(scalerOptions)
if err != nil {
return err
}
err = task.Run()
if err != nil {
logrus.Fatal(err)
}
return nil
}