Files
threshold/internal/cmd/commands/genericcmd/generic.go
T
Jeff MitchellandJohan Brandhorst-Satzkorn 0bf60996c5 Add generic read/update/delete commands (#3967)
* 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.

* Update main.go

Co-authored-by: Johan Brandhorst-Satzkorn <johan.brandhorst@gmail.com>

* Update changelog and remove another deprecated command

---------

Co-authored-by: Johan Brandhorst-Satzkorn <johan.brandhorst@gmail.com>
2023-11-01 16:24:16 -04:00

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
}