-
Notifications
You must be signed in to change notification settings - Fork 149
/
cmd.go
54 lines (43 loc) · 1.44 KB
/
cmd.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
package app
import (
"context"
"fmt"
"os"
"github.com/weaveworks/weave-gitops/pkg/flux"
"github.com/weaveworks/weave-gitops/pkg/osys"
"github.com/weaveworks/weave-gitops/pkg/runner"
"github.com/weaveworks/weave-gitops/pkg/services"
"github.com/pkg/errors"
"github.com/spf13/cobra"
"github.com/weaveworks/weave-gitops/cmd/gitops/version"
"github.com/weaveworks/weave-gitops/cmd/internal"
"github.com/weaveworks/weave-gitops/pkg/services/app"
)
var params app.PauseParams
var Cmd = &cobra.Command{
Use: "app <app-name>",
Short: "Suspend an application",
Args: cobra.MinimumNArgs(1),
Example: "gitops suspend app podinfo",
RunE: runCmd,
SilenceUsage: true,
SilenceErrors: true,
PostRun: func(cmd *cobra.Command, args []string) {
version.CheckVersion(version.CheckpointParamsWithFlags(version.CheckpointParams(), cmd))
},
}
func runCmd(cmd *cobra.Command, args []string) error {
ctx := context.Background()
params.Namespace, _ = cmd.Parent().Flags().GetString("namespace")
params.Name = args[0]
fluxClient := flux.New(osys.New(), &runner.CLIRunner{})
factory := services.NewFactory(fluxClient, internal.NewCLILogger(os.Stdout))
appService, err := factory.GetAppService(ctx)
if err != nil {
return fmt.Errorf("failed to create app service: %w", err)
}
if err := appService.Pause(params); err != nil {
return errors.Wrapf(err, "failed to pause the app %s", params.Name)
}
return nil
}