Skip to content

Commit

Permalink
Merge pull request #45 from latitudesh/fix/runtime-options
Browse files Browse the repository at this point in the history
fix: project flag missing from commands
  • Loading branch information
ynhummel committed May 29, 2024
2 parents c4fed30 + 21562a0 commit 279d4d5
Show file tree
Hide file tree
Showing 10 changed files with 59 additions and 56 deletions.
17 changes: 7 additions & 10 deletions cli/create_server_operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,23 +103,20 @@ func (o *CreateServerOperation) registerFlags(cmd *cobra.Command) {
Description: "User data to set on the server",
Required: false,
},
}

o.BodyAttributesFlags.Register(schema)
}

func (o *CreateServerOperation) preRun(cmd *cobra.Command, args []string) {
projects := fetchUserProjects()
schema := &cmdflag.FlagsSchema{
&cmdflag.String{
Name: "project",
Label: "Project",
Description: "The project (ID or Slug) to deploy the server",
Required: true,
Options: projects,
},
}
o.BodyAttributesFlags.AppendFlags(schema)

o.BodyAttributesFlags.Register(schema)
}

func (o *CreateServerOperation) preRun(cmd *cobra.Command, args []string) {
projects := fetchUserProjects()
o.BodyAttributesFlags.AddFlagOption("project", projects)

o.BodyAttributesFlags.PreRun(cmd, args)
}
Expand Down
17 changes: 7 additions & 10 deletions cli/create_virtual_network_operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,23 +57,20 @@ func (o *CreateVirtualNetworkOperation) registerFlags(cmd *cobra.Command) {
Options: virtualNetwork.SupportedSites,
Required: false,
},
}

o.BodyAttributesFlags.Register(schema)
}

func (o *CreateVirtualNetworkOperation) preRun(cmd *cobra.Command, args []string) {
projects := fetchUserProjects()
schema := &cmdflag.FlagsSchema{
&cmdflag.String{
Name: "project",
Label: "Project ID or Slug",
Description: "Project ID or Slug",
Required: true,
Options: projects,
},
}
o.BodyAttributesFlags.AppendFlags(schema)

o.BodyAttributesFlags.Register(schema)
}

func (o *CreateVirtualNetworkOperation) preRun(cmd *cobra.Command, args []string) {
projects := fetchUserProjects()
o.BodyAttributesFlags.AddFlagOption("project", projects)

o.BodyAttributesFlags.PreRun(cmd, args)
}
Expand Down
17 changes: 7 additions & 10 deletions cli/delete_project_ssh_key_operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,23 +48,20 @@ func (o *DeleteSSHKeyOperation) registerFlags(cmd *cobra.Command) {
Description: "ID from the SSH Key you want to update",
Required: true,
},
}

o.PathParamFlags.Register(schema)
}

func (o *DeleteSSHKeyOperation) preRun(cmd *cobra.Command, args []string) {
projects := fetchUserProjects()
schema := &cmdflag.FlagsSchema{
&cmdflag.String{
Name: "project",
Label: "Project ID or Slug",
Description: "Project ID or Slug",
Required: true,
Options: projects,
},
}
o.PathParamFlags.AppendFlags(schema)

o.PathParamFlags.Register(schema)
}

func (o *DeleteSSHKeyOperation) preRun(cmd *cobra.Command, args []string) {
projects := fetchUserProjects()
o.PathParamFlags.AddFlagOption("project", projects)

o.PathParamFlags.PreRun(cmd, args)
}
Expand Down
19 changes: 8 additions & 11 deletions cli/post_project_ssh_key_operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,13 @@ func (o *CreateSSHKeyOperation) registerFlags(cmd *cobra.Command) {
o.PathParamFlags = cmdflag.Flags{FlagSet: cmd.Flags()}
o.BodyAttributesFlags = cmdflag.Flags{FlagSet: cmd.Flags()}

pathParamsSchema := &cmdflag.FlagsSchema{}
pathParamsSchema := &cmdflag.FlagsSchema{
&cmdflag.String{
Name: "project",
Label: "Project ID or Slug",
Description: "Project ID or Slug",
Required: true,
}}

bodyFlagsSchema := &cmdflag.FlagsSchema{
&cmdflag.String{
Expand All @@ -66,16 +72,7 @@ func (o *CreateSSHKeyOperation) registerFlags(cmd *cobra.Command) {

func (o *CreateSSHKeyOperation) preRun(cmd *cobra.Command, args []string) {
projects := fetchUserProjects()
schema := &cmdflag.FlagsSchema{
&cmdflag.String{
Name: "project",
Label: "ID or Slug from the project you want to add the SSH Key",
Description: "ID or Slug from the project you want to add the SSH Key",
Required: true,
Options: projects,
},
}
o.PathParamFlags.AppendFlags(schema)
o.PathParamFlags.AddFlagOption("project", projects)

o.PathParamFlags.PreRun(cmd, args)
o.BodyAttributesFlags.PreRun(cmd, args)
Expand Down
17 changes: 7 additions & 10 deletions cli/put_project_ssh_key_operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ func (o *UpdateSSHKeyOperation) registerFlags(cmd *cobra.Command) {
Description: "ID from the SSH Key you want to update",
Required: true,
},
&cmdflag.String{
Name: "project",
Label: "Project ID or Slug",
Description: "Project ID or Slug",
Required: true,
},
}

bodyFlagsSchema := &cmdflag.FlagsSchema{
Expand All @@ -73,16 +79,7 @@ func (o *UpdateSSHKeyOperation) registerFlags(cmd *cobra.Command) {

func (o *UpdateSSHKeyOperation) preRun(cmd *cobra.Command, args []string) {
projects := fetchUserProjects()
schema := &cmdflag.FlagsSchema{
&cmdflag.String{
Name: "project",
Label: "Project ID or Slug",
Description: "Project ID or Slug",
Required: true,
Options: projects,
},
}
o.PathParamFlags.AppendFlags(schema)
o.PathParamFlags.AddFlagOption("project", projects)

o.PathParamFlags.PreRun(cmd, args)
o.BodyAttributesFlags.PreRun(cmd, args)
Expand Down
4 changes: 4 additions & 0 deletions internal/cmdflag/bool.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,7 @@ func (f *Bool) description() string {

return fmt.Sprintf("[Required] %v", f.Description)
}

func (f *Bool) UpdateOptions(options interface{}) {
//Function needed to implement interface
}
4 changes: 4 additions & 0 deletions internal/cmdflag/int64.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,7 @@ func (f *Int64) description() string {

return fmt.Sprintf("[Required] %v", f.Description)
}

func (f *Int64) UpdateOptions(options interface{}) {
//Function needed to implement interface
}
11 changes: 6 additions & 5 deletions internal/cmdflag/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (

type FlagSchema interface {
Register(f *pflag.FlagSet)
UpdateOptions(options interface{})
GetValue() interface{}
GetName() string
Prompt() prompt.PromptInput
Expand All @@ -35,11 +36,11 @@ func (f *Flags) Register(s *FlagsSchema) {
}
}

func (f *Flags) AppendFlags(s *FlagsSchema) {
*f.schema = append(*f.schema, *s...)

for _, v := range *s {
v.Register(f.FlagSet)
func (f *Flags) AddFlagOption(flagName string, option []string) {
for _, flag := range *f.schema {
if flag.GetName() == flagName {
flag.UpdateOptions(option)
}
}
}

Expand Down
5 changes: 5 additions & 0 deletions internal/cmdflag/string.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,8 @@ func (f *String) description() string {

return fmt.Sprintf("[Required] %v", f.Description)
}

func (f *String) UpdateOptions(options interface{}) {
option := options.([]string)
f.Options = append(f.Options, option...)
}
4 changes: 4 additions & 0 deletions internal/cmdflag/string_slice.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,7 @@ func (f *StringSlice) description() string {

return fmt.Sprintf("[Required] %v", f.Description)
}

func (f *StringSlice) UpdateOptions(options interface{}) {
//Function needed to implement interface
}

0 comments on commit 279d4d5

Please sign in to comment.