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
@@ -0,0 +1,44 @@
|
||||
// Copyright (c) HashiCorp, Inc.
|
||||
// SPDX-License-Identifier: BUSL-1.1
|
||||
|
||||
package genericcmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/hashicorp/boundary/internal/cmd/base"
|
||||
"github.com/mitchellh/cli"
|
||||
)
|
||||
|
||||
var _ cli.Command = (*Command)(nil)
|
||||
|
||||
type Command struct {
|
||||
*base.Command
|
||||
|
||||
Func string
|
||||
}
|
||||
|
||||
func (c *Command) Synopsis() string {
|
||||
return fmt.Sprintf("Run a generic %s command against a resource", c.Func)
|
||||
}
|
||||
|
||||
func (c *Command) Help() string {
|
||||
aAn := "a"
|
||||
if c.Func == "update" {
|
||||
aAn = "an"
|
||||
}
|
||||
return base.WrapForHelpText([]string{
|
||||
fmt.Sprintf("Usage: boundary %s [resource ID] [args]", c.Func),
|
||||
"",
|
||||
fmt.Sprintf(" This command runs %s %s command against the given resource ID. Arguments are the same as the type-specific command.", aAn, c.Func),
|
||||
"",
|
||||
fmt.Sprintf(" Note: this command forwards to a type-specific command; help/error/cURL output from that command may show the full command syntax."),
|
||||
})
|
||||
}
|
||||
|
||||
func (c *Command) Run(args []string) int {
|
||||
if len(args) > 0 {
|
||||
return cli.RunResultHelp
|
||||
}
|
||||
return base.CommandSuccess
|
||||
}
|
||||
Reference in new issue
Block a user