Skip to content

Commit

Permalink
Adding WithListall option (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidjumani authored Oct 7, 2021
1 parent b72a0ae commit 506cb4a
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
20 changes: 20 additions & 0 deletions cloudstack/cloudstack.go
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,26 @@ func WithHTTPClient(client *http.Client) ClientOption {
}
}

// ListallSetter is an interface that every type that can set listall must implement
type ListallSetter interface {
SetListall(bool)
}

// WithListall takes either a project name or ID and sets the `listall` parameter
func WithListall(listall bool) OptionFunc {
return func(cs *CloudStackClient, p interface{}) error {
ps, ok := p.(ListallSetter)

if !ok {
return nil
}

ps.SetListall(listall)

return nil
}
}

// ProjectIDSetter is an interface that every type that can set a project ID must implement
type ProjectIDSetter interface {
SetProjectid(string)
Expand Down
19 changes: 19 additions & 0 deletions generate/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,25 @@ func (as *allServices) GeneralCode() ([]byte, error) {
pn(" }")
pn("}")
pn("")
pn("// ListallSetter is an interface that every type that can set listall must implement")
pn("type ListallSetter interface {")
pn(" SetListall(bool)")
pn("}")
pn("")
pn("// WithListall takes either a project name or ID and sets the `listall` parameter")
pn("func WithListall(listall bool) OptionFunc {")
pn(" return func(cs *CloudStackClient, p interface{}) error {")
pn(" ps, ok := p.(ListallSetter)")
pn("")
pn(" if !ok {")
pn(" return nil")
pn(" }")
pn("")
pn(" ps.SetListall(listall)")
pn("")
pn(" return nil")
pn(" }")
pn("}")
pn("// ProjectIDSetter is an interface that every type that can set a project ID must implement")
pn("type ProjectIDSetter interface {")
pn(" SetProjectid(string)")
Expand Down

0 comments on commit 506cb4a

Please sign in to comment.