import ( "fmt" "github.com/cloudfoundry/cli/cf/commandregistry" "github.com/cloudfoundry/cli/cf/flags" "github.com/cloudfoundry/cli/cf/requirements" ) func init() { commandregistry.Register(&myCommand{}) } type myCommand struct{} func (c *myCommand) Metadata() commandregistry.CommandMetadata { return commandregistry.CommandMetadata{ Name: "my-command", Description: "This is my command", } } func (c *myCommand) Requirements(requirementsFactory requirements.Factory, fc flags.FlagContext) ([]requirements.Requirement, error) { return nil, nil } func (c *myCommand) SetDependency(deps commandregistry.Dependency, pluginCall bool) commandregistry.Command { return c } func (c *myCommand) Execute(cxt flags.FlagContext) error { fmt.Println("Hello, World!") return nil }
import ( "fmt" "github.com/cloudfoundry/cli/cf/commandregistry" ) func main() { registry := commandregistry.Commands for _, cmd := range registry { fmt.Println(cmd.Metadata().Name) } }This example shows how to get a list of all registered commands in the command registry. The "Commands" variable is a slice of all registered commands, and we can iterate over it to get the name of each command.