* 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>
45 lines
1.0 KiB
Go
45 lines
1.0 KiB
Go
// 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
|
|
}
|