Skip to content

Commit

Permalink
fix: config flags, typos
Browse files Browse the repository at this point in the history
  • Loading branch information
itnpeople committed Apr 4, 2022
1 parent b51df17 commit 689ddcc
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 50 deletions.
13 changes: 5 additions & 8 deletions cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ func Execute() {
}

type CBCtlOptions struct {
app.ConfigContext
app.IOStreams
PluginHandler

Expand Down Expand Up @@ -100,19 +99,17 @@ func NewCBCtlCommand(o CBCtlOptions) *cobra.Command {
output := app.Output{Type: &o.Output, Stream: o.IOStreams.Out}
cmds.AddCommand(NewCmdVersion(o.IOStreams))
cmds.AddCommand(NewCmdConfig(output))
cmds.AddCommand(mcks.NewCmdCluster(o.ConfigContext, output))
cmds.AddCommand(mcks.NewCmdCluster(output))
cmds.AddCommand(mcks.NewCmdNodes(output))
cmds.AddCommand(spider.NewCmdDriver(o.ConfigContext, output))
cmds.AddCommand(spider.NewCmdCredential(o.ConfigContext, output))
cmds.AddCommand(spider.NewCmdRegion(o.ConfigContext, output))
cmds.AddCommand(spider.NewCmdConnection(o.ConfigContext, output))
cmds.AddCommand(spider.NewCmdDriver(output))
cmds.AddCommand(spider.NewCmdCredential(output))
cmds.AddCommand(spider.NewCmdRegion(output))
cmds.AddCommand(spider.NewCmdConnection(output))
cmds.AddCommand(NewCmdPlugin(o.IOStreams))

cobra.OnInitialize(func() {
if err := app.OnConfigInitialize(cfgFile); err != nil {
fmt.Println(err.Error())
} else {
o.ConfigContext = *app.Config.GetCurrentContext()
}
})

Expand Down
16 changes: 7 additions & 9 deletions cmd/mcks/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (

// a struct to support command
type ClusterOptions struct {
app.ConfigContext
app.Output
RootUrl string
Namespace string
Expand All @@ -33,20 +32,19 @@ type ClusterOptions struct {
}

// returns initialized Options
func NewClusterOptions(ctx app.ConfigContext, output app.Output) *ClusterOptions {
func NewClusterOptions(output app.Output) *ClusterOptions {
return &ClusterOptions{
ConfigContext: ctx,
Output: output,
Output: output,
}
}

// completes all the required options
func (o *ClusterOptions) Complete(cmd *cobra.Command) error {
o.RootUrl = utils.NVL(o.RootUrl, o.ConfigContext.Urls.MCKS)
o.RootUrl = utils.NVL(o.RootUrl, app.Config.GetCurrentContext().Urls.MCKS)
if !strings.HasPrefix(o.RootUrl, "http://") && !strings.HasPrefix(o.RootUrl, "https://") {
return fmt.Errorf("Invalid request roo-url flag (%s)", o.RootUrl)
return fmt.Errorf("Invalid request root-url flag (%s)", o.RootUrl)
}
o.Namespace = utils.NVL(o.Namespace, o.ConfigContext.Namespace)
o.Namespace = utils.NVL(o.Namespace, app.Config.GetCurrentContext().Namespace)
if o.Namespace == "" {
return fmt.Errorf("Invalid namespace flag")
}
Expand All @@ -67,8 +65,8 @@ func (o *ClusterOptions) Validate() error {
}

// returns a cobra command
func NewCmdCluster(ctx app.ConfigContext, output app.Output) *cobra.Command {
o := NewClusterOptions(ctx, output)
func NewCmdCluster(output app.Output) *cobra.Command {
o := NewClusterOptions(output)

// root
cmds := &cobra.Command{
Expand Down
14 changes: 6 additions & 8 deletions cmd/spider/connecton.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (

// a struct to support command
type ConnectionOptions struct {
app.ConfigContext
app.Output
RootUrl string
Name string
Expand All @@ -23,18 +22,17 @@ type ConnectionOptions struct {
}

// returns initialized Options
func NewConnectionOptions(ctx app.ConfigContext, output app.Output) *ConnectionOptions {
func NewConnectionOptions(output app.Output) *ConnectionOptions {
return &ConnectionOptions{
ConfigContext: ctx,
Output: output,
Output: output,
}
}

// completes all the required options
func (o *ConnectionOptions) Complete(cmd *cobra.Command) error {
o.RootUrl = utils.NVL(o.RootUrl, o.ConfigContext.Urls.Spider)
o.RootUrl = utils.NVL(o.RootUrl, app.Config.GetCurrentContext().Urls.Spider)
if !strings.HasPrefix(o.RootUrl, "http://") && !strings.HasPrefix(o.RootUrl, "https://") {
return fmt.Errorf("Invalid request roo-url flag (%s)", o.RootUrl)
return fmt.Errorf("Invalid request root-url flag (%s)", o.RootUrl)
}
return nil
}
Expand All @@ -57,8 +55,8 @@ func (o *ConnectionOptions) Validate() error {
}

// returns a cobra command
func NewCmdConnection(ctx app.ConfigContext, output app.Output) *cobra.Command {
o := NewConnectionOptions(ctx, output)
func NewCmdConnection(output app.Output) *cobra.Command {
o := NewConnectionOptions(output)
cmds := &cobra.Command{
Use: "connection",
Short: "Cloud connection info.",
Expand Down
14 changes: 6 additions & 8 deletions cmd/spider/credential.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (

// a struct to support command
type CredentialOptions struct {
app.ConfigContext
app.Output
RootUrl string
CSP string
Expand All @@ -29,18 +28,17 @@ type CredentialOptions struct {
}

// returns initialized Options
func NewCredentialOptions(ctx app.ConfigContext, output app.Output) *CredentialOptions {
func NewCredentialOptions(output app.Output) *CredentialOptions {
return &CredentialOptions{
ConfigContext: ctx,
Output: output,
Output: output,
}
}

// completes all the required options
func (o *CredentialOptions) Complete(cmd *cobra.Command) error {
o.RootUrl = utils.NVL(o.RootUrl, o.ConfigContext.Urls.Spider)
o.RootUrl = utils.NVL(o.RootUrl, app.Config.GetCurrentContext().Urls.Spider)
if !strings.HasPrefix(o.RootUrl, "http://") && !strings.HasPrefix(o.RootUrl, "https://") {
return fmt.Errorf("Invalid request roo-url flag (%s)", o.RootUrl)
return fmt.Errorf("Invalid request root-url flag (%s)", o.RootUrl)
}
return nil
}
Expand Down Expand Up @@ -75,8 +73,8 @@ func (o *CredentialOptions) Validate() error {
}

// returns a cobra command
func NewCmdCredential(ctx app.ConfigContext, output app.Output) *cobra.Command {
o := NewCredentialOptions(ctx, output)
func NewCmdCredential(output app.Output) *cobra.Command {
o := NewCredentialOptions(output)
cmds := &cobra.Command{
Use: "credential",
Short: "Cloud credential",
Expand Down
14 changes: 6 additions & 8 deletions cmd/spider/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,22 @@ import (
// a struct to support command
type DriverOptions struct {
app.Output
app.ConfigContext
RootUrl string
CSP string
}

// returns initialized Options
func NewDriverOptions(ctx app.ConfigContext, output app.Output) *DriverOptions {
func NewDriverOptions(output app.Output) *DriverOptions {
return &DriverOptions{
ConfigContext: ctx,
Output: output,
Output: output,
}
}

// completes all the required options
func (o *DriverOptions) Complete(cmd *cobra.Command) error {
o.RootUrl = utils.NVL(o.RootUrl, o.ConfigContext.Urls.Spider)
o.RootUrl = utils.NVL(o.RootUrl, app.Config.GetCurrentContext().Urls.Spider)
if !strings.HasPrefix(o.RootUrl, "http://") && !strings.HasPrefix(o.RootUrl, "https://") {
return fmt.Errorf("Invalid request roo-url flag (%s)", o.RootUrl)
return fmt.Errorf("Invalid request root-url flag (%s)", o.RootUrl)
}
return nil
}
Expand All @@ -45,8 +43,8 @@ func (o *DriverOptions) Validate() error {
}

// returns a cobra command
func NewCmdDriver(ctx app.ConfigContext, output app.Output) *cobra.Command {
o := NewDriverOptions(ctx, output)
func NewCmdDriver(output app.Output) *cobra.Command {
o := NewDriverOptions(output)
cmds := &cobra.Command{
Use: "driver",
Short: "Cloud driver",
Expand Down
14 changes: 6 additions & 8 deletions cmd/spider/region.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (

// a struct to support command
type RegionOptions struct {
app.ConfigContext
app.Output
RootUrl string
CSP string
Expand All @@ -25,18 +24,17 @@ type RegionOptions struct {
}

// returns initialized Options
func NewRegionOptions(ctx app.ConfigContext, output app.Output) *RegionOptions {
func NewRegionOptions(output app.Output) *RegionOptions {
return &RegionOptions{
ConfigContext: ctx,
Output: output,
Output: output,
}
}

// completes all the required options
func (o *RegionOptions) Complete(cmd *cobra.Command) error {
o.RootUrl = utils.NVL(o.RootUrl, o.ConfigContext.Urls.Spider)
o.RootUrl = utils.NVL(o.RootUrl, app.Config.GetCurrentContext().Urls.Spider)
if !strings.HasPrefix(o.RootUrl, "http://") && !strings.HasPrefix(o.RootUrl, "https://") {
return fmt.Errorf("Invalid request roo-url flag (%s)", o.RootUrl)
return fmt.Errorf("Invalid request root-url flag (%s)", o.RootUrl)
}
return nil
}
Expand All @@ -53,8 +51,8 @@ func (o *RegionOptions) Validate() error {
}

// returns a cobra command
func NewCmdRegion(ctx app.ConfigContext, output app.Output) *cobra.Command {
o := NewRegionOptions(ctx, output)
func NewCmdRegion(output app.Output) *cobra.Command {
o := NewRegionOptions(output)
cmds := &cobra.Command{
Use: "region",
Short: "Cloud region",
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ require (
github.com/mitchellh/mapstructure v1.4.3
github.com/spf13/cobra v1.3.0
github.com/spf13/viper v1.10.1
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b
k8s.io/client-go v0.23.4
)

Expand Down Expand Up @@ -43,7 +44,6 @@ require (
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/ini.v1 v1.66.2 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
k8s.io/apimachinery v0.23.4 // indirect
k8s.io/klog/v2 v2.30.0 // indirect
k8s.io/utils v0.0.0-20211116205334-6203023598ed // indirect
Expand Down

0 comments on commit 689ddcc

Please sign in to comment.