package main import ( "fmt" "os" cfplugin "github.com/cloudfoundry/cli/plugin" ) // ExampleCliCommand is an example implementation of the cli.Plugin interface type ExampleCliCommand struct {} func (c *ExampleCliCommand) Run(cliConnection cfplugin.CliConnection, args []string) { fmt.Println("Hello World!") } func (c *ExampleCliCommand) GetMetadata() cfplugin.PluginMetadata { return cfplugin.PluginMetadata{ Name: "example-cli-command", Version: cfplugin.VersionType{ Major: 1, Minor: 0, Build: 0, }, Commands: []cfplugin.Command{ { Name: "example-cli-command", HelpText: "A simple example CLI command", }, }, } } func main() { // Instantiate ExampleCliCommand cliCommand := &ExampleCliCommand{} // Start the plugin plugin.Start(cliCommand) }
package main import ( "fmt" "os" cfplugin "github.com/cloudfoundry/cli/plugin" ) func main() { // Connect to the CF CLI connection, err := cfplugin.NewConnection(nil) if err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(1) } defer connection.Close() // Get the list of available organizations orgs, err := connection.GetOrganizations() if err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(1) } fmt.Println("Available Organizations:") for _, org := range orgs { fmt.Println(org.Name) } }Description: This example code demonstrates how to use the `CliConnection` package to connect to the CF CLI and retrieve a list of available organizations. It first creates a new connection using `NewConnection`, passing in `nil` for the `config` argument. The `GetOrganizations` method is then called on the connection object to retrieve a slice of `cfplugin.Organization` structs, containing details about each organization. Finally, the list of organization names is printed to the console.