Skip to content

Commit 506cb4a

Browse files
authored
Adding WithListall option (#13)
1 parent b72a0ae commit 506cb4a

2 files changed

Lines changed: 39 additions & 0 deletions

File tree

cloudstack/cloudstack.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,26 @@ func WithHTTPClient(client *http.Client) ClientOption {
487487
}
488488
}
489489

490+
// ListallSetter is an interface that every type that can set listall must implement
491+
type ListallSetter interface {
492+
SetListall(bool)
493+
}
494+
495+
// WithListall takes either a project name or ID and sets the `listall` parameter
496+
func WithListall(listall bool) OptionFunc {
497+
return func(cs *CloudStackClient, p interface{}) error {
498+
ps, ok := p.(ListallSetter)
499+
500+
if !ok {
501+
return nil
502+
}
503+
504+
ps.SetListall(listall)
505+
506+
return nil
507+
}
508+
}
509+
490510
// ProjectIDSetter is an interface that every type that can set a project ID must implement
491511
type ProjectIDSetter interface {
492512
SetProjectid(string)

generate/generate.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,25 @@ func (as *allServices) GeneralCode() ([]byte, error) {
585585
pn(" }")
586586
pn("}")
587587
pn("")
588+
pn("// ListallSetter is an interface that every type that can set listall must implement")
589+
pn("type ListallSetter interface {")
590+
pn(" SetListall(bool)")
591+
pn("}")
592+
pn("")
593+
pn("// WithListall takes either a project name or ID and sets the `listall` parameter")
594+
pn("func WithListall(listall bool) OptionFunc {")
595+
pn(" return func(cs *CloudStackClient, p interface{}) error {")
596+
pn(" ps, ok := p.(ListallSetter)")
597+
pn("")
598+
pn(" if !ok {")
599+
pn(" return nil")
600+
pn(" }")
601+
pn("")
602+
pn(" ps.SetListall(listall)")
603+
pn("")
604+
pn(" return nil")
605+
pn(" }")
606+
pn("}")
588607
pn("// ProjectIDSetter is an interface that every type that can set a project ID must implement")
589608
pn("type ProjectIDSetter interface {")
590609
pn(" SetProjectid(string)")

0 commit comments

Comments
 (0)