Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 7 additions & 35 deletions cmd/pro/check_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import (
"github.com/devsy-org/devsy/cmd/pro/flags"
"github.com/devsy-org/devsy/cmd/pro/proutil"
"github.com/devsy-org/devsy/pkg/config"
cliflags "github.com/devsy-org/devsy/pkg/flags"
"github.com/devsy-org/devsy/pkg/flags/names"
"github.com/devsy-org/devsy/pkg/platform"
"github.com/devsy-org/devsy/pkg/provider"
"github.com/devsy-org/devsy/pkg/telemetry"
Expand All @@ -25,45 +23,19 @@ type CheckUpdateCmd struct {
}

// NewCheckUpdateCmd creates a new command.
//
//nolint:dupl // structurally similar to NewHealthCmd; intentional sibling factory
func NewCheckUpdateCmd(globalFlags *flags.GlobalFlags) *cobra.Command {
cmd := &CheckUpdateCmd{
GlobalFlags: globalFlags,
}
c := &cobra.Command{
Use: "check-update",
Short: "Check platform provider update",
Hidden: true,
Annotations: telemetry.SkipInUIAnnotation(),
RunE: func(cobraCmd *cobra.Command, args []string) error {
devsyConfig, provider, err := proutil.FindProProvider(
cobraCmd.Context(),
cmd.Context,
cmd.Provider,
cmd.Host,
)
if err != nil {
return err
}

return cmd.Run(cobraCmd.Context(), devsyConfig, provider)
},
PersistentPreRun: func(cmd *cobra.Command, args []string) {
root := cmd.Root()
if root == nil {
return
}
if root.Annotations == nil {
root.Annotations = map[string]string{}
}
root.Annotations[config.AgentExecutedAnnotation] = "true" //nolint:goconst
},
Use: "check-update",
Short: "Check platform provider update",
Hidden: true,
Annotations: telemetry.SkipInUIAnnotation(),
RunE: proutil.HostRunE(globalFlags, &cmd.Host, cmd.Run),
PersistentPreRun: proutil.MarkAgentExecuted,
}

cliflags.Add(c, cliflags.String(&cmd.Host, names.Host, "", "The pro instance to use"))
_ = c.MarkFlagRequired(names.Host)
flags.BindEnv(c.Flags(), names.Host)
proutil.AddHostFlag(c, &cmd.Host)

return c
}
Expand Down
19 changes: 2 additions & 17 deletions cmd/pro/cluster/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,9 @@ func NewListCmd(globalFlags *flags.GlobalFlags) *cobra.Command {
Use: "list",
Short: "List clusters",
Hidden: true,
RunE: func(cobraCmd *cobra.Command, args []string) error {
devsyConfig, provider, err := proutil.FindProProvider(
cobraCmd.Context(),
cmd.Context,
cmd.Provider,
cmd.Host,
)
if err != nil {
return err
}

return cmd.Run(cobraCmd.Context(), devsyConfig, provider)
},
RunE: proutil.HostRunE(globalFlags, &cmd.Host, cmd.Run),
}

cliflags.Add(c, cliflags.String(&cmd.Host, names.Host, "", "The pro instance to use"))
_ = c.MarkFlagRequired(names.Host)
flags.BindEnv(c.Flags(), names.Host)
proutil.AddHostFlag(c, &cmd.Host)
cliflags.Add(c, cliflags.String(&cmd.Project, names.Project, "", "The project to use"))
_ = c.MarkFlagRequired(names.Project)
flags.BindEnv(c.Flags(), names.Project)
Expand Down
52 changes: 5 additions & 47 deletions cmd/pro/daemon/netcheck.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,10 @@ import (
"fmt"
"strconv"

"github.com/devsy-org/devsy/cmd/pro/completion"
proflags "github.com/devsy-org/devsy/cmd/pro/flags"
"github.com/devsy-org/devsy/cmd/pro/proutil"
"github.com/devsy-org/devsy/pkg/config"
daemon "github.com/devsy-org/devsy/pkg/daemon/platform"
cliflags "github.com/devsy-org/devsy/pkg/flags"
"github.com/devsy-org/devsy/pkg/flags/names"
providerpkg "github.com/devsy-org/devsy/pkg/provider"
"github.com/devsy-org/devsy/pkg/table"
"github.com/spf13/cobra"
Expand All @@ -27,56 +24,17 @@ type NetcheckCmd struct {
}

// NewNetcheckCmd creates a new command.
//
//nolint:dupl // structurally similar to NewStatusCmd; intentional sibling factory
func NewNetcheckCmd(flags *proflags.GlobalFlags) *cobra.Command {
cmd := &NetcheckCmd{
GlobalFlags: flags,
}
c := &cobra.Command{
Use: "netcheck",
Short: "Get the status of the current network",
RunE: func(cobraCmd *cobra.Command, args []string) error {
devsyConfig, provider, err := proutil.FindProProvider(
cobraCmd.Context(),
cmd.Context,
cmd.Provider,
cmd.Host,
)
if err != nil {
return err
}

return cmd.Run(cobraCmd.Context(), devsyConfig, provider)
},
PersistentPreRun: func(cmd *cobra.Command, args []string) {
root := cmd.Root()
if root == nil {
return
}
if root.Annotations == nil {
root.Annotations = map[string]string{}
}
root.Annotations[config.AgentExecutedAnnotation] = "true"
},
Use: "netcheck",
Short: "Get the status of the current network",
RunE: proutil.HostRunE(flags, &cmd.Host, cmd.Run),
PersistentPreRun: proutil.MarkAgentExecuted,
}

cliflags.Add(c, cliflags.String(&cmd.Host, names.Host, "", "The pro instance to use"))
_ = c.MarkFlagRequired(names.Host)
proflags.BindEnv(c.Flags(), names.Host)
_ = c.RegisterFlagCompletionFunc(
names.Host,
func(rootCmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
return completion.GetPlatformHostSuggestions(
rootCmd,
cmd.Context,
cmd.Provider,
args,
toComplete,
cmd.Owner,
)
},
)
proutil.AddHostFlag(c, &cmd.Host, proutil.WithHostCompletion(flags))

return c
}
Expand Down
35 changes: 2 additions & 33 deletions cmd/pro/daemon/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,10 @@ import (
"syscall"

managementv1 "github.com/devsy-org/api/pkg/apis/management/v1"
"github.com/devsy-org/devsy/cmd/pro/completion"
proflags "github.com/devsy-org/devsy/cmd/pro/flags"
"github.com/devsy-org/devsy/cmd/pro/proutil"
"github.com/devsy-org/devsy/pkg/config"
daemon "github.com/devsy-org/devsy/pkg/daemon/platform"
cliflags "github.com/devsy-org/devsy/pkg/flags"
"github.com/devsy-org/devsy/pkg/flags/names"
"github.com/devsy-org/devsy/pkg/log"
"github.com/devsy-org/devsy/pkg/platform/client"
providerpkg "github.com/devsy-org/devsy/pkg/provider"
Expand All @@ -38,37 +35,9 @@ func NewStartCmd(flags *proflags.GlobalFlags) *cobra.Command {
c := &cobra.Command{
Use: "start",
Short: "Start the client daemon",
RunE: func(cobraCmd *cobra.Command, args []string) error {
devsyConfig, provider, err := proutil.FindProProvider(
cobraCmd.Context(),
cmd.Context,
cmd.Provider,
cmd.Host,
)
if err != nil {
return err
}

return cmd.Run(cobraCmd.Context(), devsyConfig, provider)
},
RunE: proutil.HostRunE(flags, &cmd.Host, cmd.Run),
}

cliflags.Add(c, cliflags.String(&cmd.Host, names.Host, "", "The pro instance to use"))
_ = c.MarkFlagRequired(names.Host)
proflags.BindEnv(c.Flags(), names.Host)
_ = c.RegisterFlagCompletionFunc(
names.Host,
func(rootCmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
return completion.GetPlatformHostSuggestions(
rootCmd,
cmd.Context,
cmd.Provider,
args,
toComplete,
cmd.Owner,
)
},
)
proutil.AddHostFlag(c, &cmd.Host, proutil.WithHostCompletion(flags))

return c
}
Expand Down
52 changes: 5 additions & 47 deletions cmd/pro/daemon/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,10 @@ import (
"encoding/json"
"fmt"

"github.com/devsy-org/devsy/cmd/pro/completion"
proflags "github.com/devsy-org/devsy/cmd/pro/flags"
"github.com/devsy-org/devsy/cmd/pro/proutil"
"github.com/devsy-org/devsy/pkg/config"
platformdaemon "github.com/devsy-org/devsy/pkg/daemon/platform"
cliflags "github.com/devsy-org/devsy/pkg/flags"
"github.com/devsy-org/devsy/pkg/flags/names"
providerpkg "github.com/devsy-org/devsy/pkg/provider"
"github.com/spf13/cobra"
)
Expand All @@ -24,56 +21,17 @@ type StatusCmd struct {
}

// NewStatusCmd creates a new command.
//
//nolint:dupl // structurally similar to NewNetcheckCmd; intentional sibling factory
func NewStatusCmd(flags *proflags.GlobalFlags) *cobra.Command {
cmd := &StatusCmd{
GlobalFlags: flags,
}
c := &cobra.Command{
Use: "status",
Short: "Get the status of the daemon",
RunE: func(cobraCmd *cobra.Command, args []string) error {
devsyConfig, provider, err := proutil.FindProProvider(
cobraCmd.Context(),
cmd.Context,
cmd.Provider,
cmd.Host,
)
if err != nil {
return err
}

return cmd.Run(cobraCmd.Context(), devsyConfig, provider)
},
PersistentPreRun: func(cmd *cobra.Command, args []string) {
root := cmd.Root()
if root == nil {
return
}
if root.Annotations == nil {
root.Annotations = map[string]string{}
}
root.Annotations[config.AgentExecutedAnnotation] = "true"
},
Use: "status",
Short: "Get the status of the daemon",
RunE: proutil.HostRunE(flags, &cmd.Host, cmd.Run),
PersistentPreRun: proutil.MarkAgentExecuted,
}

cliflags.Add(c, cliflags.String(&cmd.Host, names.Host, "", "The pro instance to use"))
_ = c.MarkFlagRequired(names.Host)
proflags.BindEnv(c.Flags(), names.Host)
_ = c.RegisterFlagCompletionFunc(
names.Host,
func(rootCmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
return completion.GetPlatformHostSuggestions(
rootCmd,
cmd.Context,
cmd.Provider,
args,
toComplete,
cmd.Owner,
)
},
)
proutil.AddHostFlag(c, &cmd.Host, proutil.WithHostCompletion(flags))

return c
}
Expand Down
42 changes: 7 additions & 35 deletions cmd/pro/health.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import (
"github.com/devsy-org/devsy/cmd/pro/proutil"
"github.com/devsy-org/devsy/pkg/client/proxycmd"
"github.com/devsy-org/devsy/pkg/config"
cliflags "github.com/devsy-org/devsy/pkg/flags"
"github.com/devsy-org/devsy/pkg/flags/names"
"github.com/devsy-org/devsy/pkg/provider"
"github.com/devsy-org/devsy/pkg/telemetry"
"github.com/spf13/cobra"
Expand All @@ -22,45 +20,19 @@ type HealthCmd struct {
}

// NewHealthCmd creates a new command.
//
//nolint:dupl // structurally similar to NewCheckUpdateCmd; intentional sibling factory
func NewHealthCmd(globalFlags *flags.GlobalFlags) *cobra.Command {
cmd := &HealthCmd{
GlobalFlags: globalFlags,
}
c := &cobra.Command{
Use: "health",
Short: "Check platform health",
Hidden: true,
Annotations: telemetry.SkipInUIAnnotation(),
RunE: func(cobraCmd *cobra.Command, args []string) error {
devsyConfig, provider, err := proutil.FindProProvider(
cobraCmd.Context(),
cmd.Context,
cmd.Provider,
cmd.Host,
)
if err != nil {
return err
}

return cmd.Run(cobraCmd.Context(), devsyConfig, provider)
},
PersistentPreRun: func(cmd *cobra.Command, args []string) {
root := cmd.Root()
if root == nil {
return
}
if root.Annotations == nil {
root.Annotations = map[string]string{}
}
root.Annotations[config.AgentExecutedAnnotation] = "true" //nolint:goconst
},
Use: "health",
Short: "Check platform health",
Hidden: true,
Annotations: telemetry.SkipInUIAnnotation(),
RunE: proutil.HostRunE(globalFlags, &cmd.Host, cmd.Run),
PersistentPreRun: proutil.MarkAgentExecuted,
}

cliflags.Add(c, cliflags.String(&cmd.Host, names.Host, "", "The pro instance to use"))
_ = c.MarkFlagRequired(names.Host)
flags.BindEnv(c.Flags(), names.Host)
proutil.AddHostFlag(c, &cmd.Host)

return c
}
Expand Down
21 changes: 2 additions & 19 deletions cmd/pro/project/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import (
"github.com/devsy-org/devsy/cmd/pro/proutil"
"github.com/devsy-org/devsy/pkg/client/proxycmd"
"github.com/devsy-org/devsy/pkg/config"
cliflags "github.com/devsy-org/devsy/pkg/flags"
"github.com/devsy-org/devsy/pkg/flags/names"
"github.com/devsy-org/devsy/pkg/provider"
"github.com/spf13/cobra"
)
Expand All @@ -31,24 +29,9 @@ func NewListCmd(globalFlags *flags.GlobalFlags) *cobra.Command {
Use: "list",
Short: "List projects",
Hidden: true,
RunE: func(cobraCmd *cobra.Command, args []string) error {
devsyConfig, provider, err := proutil.FindProProvider(
cobraCmd.Context(),
cmd.Context,
cmd.Provider,
cmd.Host,
)
if err != nil {
return err
}

return cmd.Run(cobraCmd.Context(), devsyConfig, provider)
},
RunE: proutil.HostRunE(globalFlags, &cmd.Host, cmd.Run),
}

cliflags.Add(c, cliflags.String(&cmd.Host, names.Host, "", "The pro instance to use"))
_ = c.MarkFlagRequired(names.Host)
flags.BindEnv(c.Flags(), names.Host)
proutil.AddHostFlag(c, &cmd.Host)

return c
}
Expand Down
Loading
Loading