diff --git a/cli/deploy.go b/cli/deploy.go index 6db7c126..5d2be919 100644 --- a/cli/deploy.go +++ b/cli/deploy.go @@ -32,6 +32,7 @@ import ( emptyGAPI "github.com/purpleidea/mgmt/gapi/empty" langGAPI "github.com/purpleidea/mgmt/lang/gapi" "github.com/purpleidea/mgmt/lib" + "github.com/purpleidea/mgmt/util" "github.com/purpleidea/mgmt/util/errwrap" yamlGAPI "github.com/purpleidea/mgmt/yamlgraph" @@ -80,9 +81,10 @@ func (obj *DeployArgs) Run(ctx context.Context, data *cliUtil.Data) (bool, error } // XXX: workaround https://github.com/alexflint/go-arg/issues/239 + gapiNames := gapi.Names() // list of registered names if l := len(obj.Seeds); name == "" && l > 1 { elem := obj.Seeds[l-2] // second to last element - if elem == emptyGAPI.Name || elem == langGAPI.Name || elem == yamlGAPI.Name { + if util.StrInList(elem, gapiNames) { return false, cliUtil.CliParseError(cliUtil.MissingEquals) // consistent errors } } diff --git a/cli/run.go b/cli/run.go index 3c872465..1d0ee16b 100644 --- a/cli/run.go +++ b/cli/run.go @@ -129,10 +129,11 @@ func (obj *RunArgs) Run(ctx context.Context, data *cliUtil.Data) (bool, error) { obj.AdvertiseClientURLs, obj.AdvertiseServerURLs, } + gapiNames := gapi.Names() // list of registered names for _, list := range lists { if l := len(list); name == "" && l > 1 { elem := list[l-2] // second to last element - if elem == emptyGAPI.Name || elem == langGAPI.Name || elem == yamlGAPI.Name { + if util.StrInList(elem, gapiNames) { return false, cliUtil.CliParseError(cliUtil.MissingEquals) // consistent errors } } diff --git a/gapi/gapi.go b/gapi/gapi.go index f8428ec1..37eb5e75 100644 --- a/gapi/gapi.go +++ b/gapi/gapi.go @@ -41,6 +41,15 @@ func Register(name string, fn func() GAPI) { RegisteredGAPIs[name] = fn } +// Names returns a list of the names of all registered GAPIs. +func Names() []string { + names := []string{} + for name := range RegisteredGAPIs { + names = append(names, name) + } + return names +} + // Flags is some common data that comes from a higher-level command, and is used // by a subcommand. By type circularity, the subcommands can't easily access the // data in the parent command struct, so instead, the data that the parent wants