Add generic read/update/delete commands (#3992)
* Add generic read/update/delete commands This adds three generic commands that use the resource prefix to determine the subcommand to run and pass through args over to that subcommand. Since this occurs very early on and to avoid loading essentially every internal resource package, I moved subtype definitions to globals. This replaces #3967 Co-authored-by: Johan Brandhorst-Satzkorn <johan.brandhorst@gmail.com> * De-duplicate Subtype code (#4031) Co-authored-by: Timothy Messier <tim.messier@gmail.com> --------- Co-authored-by: Johan Brandhorst-Satzkorn <johan.brandhorst@gmail.com> Co-authored-by: Timothy Messier <tim.messier@gmail.com>
This commit is contained in:
59 files changed
+1032
-857
No files matched your search
@@ -142,12 +142,14 @@ type Command struct {
|
||||
}
|
||||
|
||||
// New returns a new instance of a base.Command type
|
||||
func NewCommand(ui cli.Ui) *Command {
|
||||
func NewCommand(ui cli.Ui, opt ...Option) *Command {
|
||||
opts := getOpts(opt...)
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
ret := &Command{
|
||||
UI: ui,
|
||||
ShutdownCh: MakeShutdownCh(),
|
||||
Context: ctx,
|
||||
FlagId: opts.withImplicitId,
|
||||
}
|
||||
go func() {
|
||||
<-ret.ShutdownCh
|
||||
|
||||
@@ -44,6 +44,7 @@ type Options struct {
|
||||
withStatusCode int
|
||||
withHostPlugin func() (string, plugin.HostPluginServiceClient)
|
||||
withEventGating bool
|
||||
withImplicitId string
|
||||
}
|
||||
|
||||
func getDefaultOptions() Options {
|
||||
@@ -200,3 +201,11 @@ func WithEventGating(with bool) Option {
|
||||
o.withEventGating = with
|
||||
}
|
||||
}
|
||||
|
||||
// WithImplicitId is used when creating the command if we are implicitly
|
||||
// overriding the ID via a top-level read/update/delete command
|
||||
func WithImplicitId(with string) Option {
|
||||
return func(o *Options) {
|
||||
o.withImplicitId = with
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user