### Getting User Input Example Source: https://github.com/bunnyshell/cli/blob/master/_autodocs/README.md Provides an example of how to ask a question to the user and handle cases where the CLI is running in non-interactive mode. ```go answer, err := interactive.Ask("Question") if errors.Is(err, interactive.ErrNonInteractive) { answer = "default" } ``` -------------------------------- ### Making API Calls Example Source: https://github.com/bunnyshell/cli/blob/master/_autodocs/README.md Demonstrates how to make an API call to get environment details, including error handling and data formatting. ```go options := environment.NewItemOptions("env-123") env, err := environment.Get(options) if err != nil { return lib.FormatCommandError(cmd, err) } return lib.FormatCommandData(cmd, env) ``` -------------------------------- ### Example: Get Environment Definition Source: https://github.com/bunnyshell/cli/blob/master/_autodocs/api-reference/environment-api.md Demonstrates how to retrieve an environment's definition using GetDefinition. Ensure you have the environment ID. ```go options := environment.NewItemOptions("env-123") def, err := environment.GetDefinition(options) if err != nil { return err } // def contains environment definition ``` -------------------------------- ### Example: Get Environment Kubeconfig Source: https://github.com/bunnyshell/cli/blob/master/_autodocs/api-reference/environment-api.md Demonstrates how to retrieve and save an environment's kubeconfig using GetKubeconfig. Requires environment ID and file system access. ```go options := environment.NewItemOptions("env-123") kubeconfig, err := environment.GetKubeconfig(options) if err != nil { return err } // Write to file or use for kubectl os.WriteFile("kubeconfig.yaml", []byte(kubeconfig), 0600) ``` -------------------------------- ### Accessing Configuration Example Source: https://github.com/bunnyshell/cli/blob/master/_autodocs/README.md Demonstrates how to retrieve global settings, such as output format and profile, from the configuration. ```go settings := config.GetSettings() format := settings.OutputFormat profile := settings.Profile ``` -------------------------------- ### Create Component Variable Example Source: https://github.com/bunnyshell/cli/blob/master/_autodocs/api-reference/component-api.md Example demonstrating how to create a new component variable with specific details. ```go // Create component variable createOpts := &component_variable.CreateOptions{ ComponentID: "comp-123", Name: "API_KEY", Value: "secret123", } variable, err := component_variable.Create(createOpts) ``` -------------------------------- ### Go Import Path Example Source: https://github.com/bunnyshell/cli/blob/master/_autodocs/README.md Demonstrates the correct import path for the configuration package in Go. ```go // Real import paths import "bunnyshell.com/cli/pkg/config" ``` -------------------------------- ### Start Environment Source: https://github.com/bunnyshell/cli/blob/master/_autodocs/api-reference/environment-api.md Starts a stopped environment. Requires options with the environment ID. ```go func Start(options *common.ItemOptions) (*sdk.EnvironmentItem, error) ``` -------------------------------- ### Example YAML Configuration Source: https://github.com/bunnyshell/cli/blob/master/_autodocs/api-reference/configuration-manager.md An example of a configuration file in YAML format, showing default profile, output format, timeout, and profile-specific settings. ```yaml defaultProfile: myprofile outputFormat: json timeout: 30s profiles: myprofile: host: environments.bunnyshell.com scheme: https token: your-token-here context: organization: org-123 project: proj-456 environment: env-789 ``` -------------------------------- ### Start Development Container Source: https://github.com/bunnyshell/cli/blob/master/CLAUDE.md Initializes the Docker-based development environment. ```bash cd .dev docker-compose up -d ``` -------------------------------- ### List Resources Example Source: https://github.com/bunnyshell/cli/blob/master/_autodocs/api-reference/api-client.md Shows how to list resources and iterate through the embedded items. Handles pagination by default. ```go options := common.NewListOptions() options.SetPage(1) items, err := environment.List(options) if err != nil { return err } for _, item := range items.Embedded { fmt.Println(item.Name) } ``` -------------------------------- ### Install Bunnyshell CLI via Generic Installer Source: https://github.com/bunnyshell/cli/blob/master/README.md Downloads and executes the installation script with a checksum verification step. ```sh installer=$(curl --silent https://raw.githubusercontent.com/bunnyshell/cli/master/installer.sh) \ && [ "33cdd268adb1e26511b0cc90c9f4bf017bb145041677ca52d23a0f93cd13bd58 *stdin" = "$(echo -n "${installer}" | openssl dgst -sha256 -r)" ] \ && ( sh -c "${installer}" || : ) \ || echo "Checksum did not match $(echo -n "${installer}" | openssl dgst -sha256 -r)" ; ``` ```sh installer=$(curl --silent https://raw.githubusercontent.com/bunnyshell/cli/master/installer.sh) \ && [ "33cdd268adb1e26511b0cc90c9f4bf017bb145041677ca52d23a0f93cd13bd58 *stdin" = "$(echo -n "${installer}" | openssl dgst -sha256 -r)" ] \ && ( SUDO_INSTALL=true INSTALL_PATH=/usr/local/bin sh -c "${installer}" || : ) \ || echo "Checksum did not match $(echo -n "${installer}" | openssl dgst -sha256 -r)" ; ``` -------------------------------- ### Define DeployOptions Struct Source: https://github.com/bunnyshell/cli/blob/master/CLAUDE.md Example of the Option pattern used for deployment configurations. ```go type DeployOptions struct { ID string WithoutPipeline bool Interval time.Duration // ... } ``` -------------------------------- ### Create Resource Example Source: https://github.com/bunnyshell/cli/blob/master/_autodocs/api-reference/api-client.md Illustrates creating a new resource with specific options. Ensure all required fields in CreateOptions are provided. ```go options := &environment.CreateOptions{ Name: "production", ProjectID: "proj-123", } env, err := environment.Create(options) if err != nil { return err } ``` -------------------------------- ### Start Environment Source: https://github.com/bunnyshell/cli/blob/master/_autodocs/api-reference/environment-api.md Starts a stopped environment. Requires options containing the environment ID. ```APIDOC ## Start Environment ### Description Starts a stopped environment. ### Method (Not specified, likely a SDK method call) ### Parameters #### Path Parameters (None specified) #### Query Parameters (None specified) #### Request Body (None specified) ### Parameters #### options (*common.ItemOptions) - Required - Options with environment ID ### Response #### Success Response - `*sdk.EnvironmentItem` - Updated environment - `error` - Error if the operation fails ### Example ```go options := environment.NewItemOptions("env-123") updatedEnv, err := environment.Start(options) if err != nil { // Handle error } // updatedEnv contains the started environment details ``` ``` -------------------------------- ### Get Raw HTTP Response Example Source: https://github.com/bunnyshell/cli/blob/master/_autodocs/api-reference/api-client.md Shows how to use the `GetRaw` function to obtain the raw HTTP response along with the data. This is useful for inspecting headers or status codes. ```go func GetRaw(options *common.ItemOptions) (*sdk.EnvironmentItem, *http.Response, error) ``` -------------------------------- ### Output Abstraction Example Source: https://github.com/bunnyshell/cli/blob/master/_autodocs/README.md Shows how to use the output formatter with different output formats like stylish, json, yaml, or raw. ```go formatter.Formatter(data, config.GetSettings().OutputFormat) ``` -------------------------------- ### Generic Installer Script Usage Source: https://github.com/bunnyshell/cli/blob/master/_autodocs/build-and-deployment.md Downloads and executes the Bunnyshell CLI installer script from a remote URL. This is a convenient way to install the CLI on various systems. ```bash curl -s https://raw.githubusercontent.com/bunnyshell/cli/master/installer.sh | \ sh ``` -------------------------------- ### Environment API Functions Source: https://github.com/bunnyshell/cli/blob/master/_autodocs/api-reference/api-client.md Lists the main functions available in the Environment API package for managing environments. These include getting, listing, deploying, cloning, creating, deleting, starting, stopping, and aborting environments. ```go func Get(options *common.ItemOptions) (*sdk.EnvironmentItem, error) func List(options *common.ListOptions) (*sdk.EnvironmentListItem, error) // Actions func Deploy(options *DeployOptions) (*sdk.DeploymentItem, error) func Clone(options *CloneOptions) (*sdk.EnvironmentItem, error) func Create(options *CreateOptions) (*sdk.EnvironmentItem, error) func Delete(options *common.ItemOptions) (*sdk.EnvironmentItem, error) func Start(options *common.ItemOptions) (*sdk.EnvironmentItem, error) func Stop(options *common.ItemOptions) (*sdk.EnvironmentItem, error) func Abort(options *AbortOptions) (*sdk.EnvironmentItem, error) // Information retrieval func GetDefinition(options *common.ItemOptions) (*sdk.EnvironmentDefinitionResponse, error) func GetKubeconfig(options *common.ItemOptions) (string, error) ``` -------------------------------- ### Install Bunnyshell CLI via Homebrew Source: https://github.com/bunnyshell/cli/blob/master/README.md Installs the CLI using the Homebrew package manager. ```sh brew install bunnyshell/tap/bunnyshell-cli ``` -------------------------------- ### Go Module File Example Source: https://github.com/bunnyshell/cli/blob/master/_autodocs/build-and-deployment.md Shows a typical go.mod file structure, including the module path, Go version, toolchain, and required dependencies with their versions. ```go module bunnyshell.com/cli go 1.23 toolchain go1.23.2 require ( bunnyshell.com/sdk v0.22.2 bunnyshell.com/dev v0.7.2 github.com/spf13/cobra v1.8.1 // ... more dependencies ) ``` -------------------------------- ### Example Configuration File Source: https://github.com/bunnyshell/cli/blob/master/_autodocs/configuration.md A sample YAML configuration file demonstrating default profile, output format, timeout, and profile-specific settings including host, scheme, token, and context details for organization, project, environment, and service component. ```yaml defaultProfile: production outputFormat: json timeout: 30s profiles: production: host: environments.bunnyshell.com scheme: https token: your-api-token-here context: organization: org-12345 project: proj-67890 environment: env-abc123 serviceComponent: comp-xyz789 staging: host: staging.environments.bunnyshell.com scheme: https token: staging-api-token context: organization: org-12345 project: proj-staging ``` -------------------------------- ### Execute Command in Component Source: https://github.com/bunnyshell/cli/blob/master/CLAUDE.md Example of the command execution flow for the bns exec utility. ```bash $ bns exec comp-123 -- ls -la ↓ cmd/exec/root.go ↓ Parses component ID from positional arg ↓ Fetches component details via pkg/api/component ↓ Retrieves kubeconfig via pkg/api/environment ↓ Interactive pod selection via pkg/wizard/k8s ↓ Interactive container selection via pkg/wizard/k8s ↓ Creates exec command via pkg/k8s/kubectl/exec ↓ Executes command in container using k8s.io/kubectl/pkg/cmd/exec ``` -------------------------------- ### Environment Lifecycle Commands Source: https://github.com/bunnyshell/cli/blob/master/_autodocs/command-structure.md Commands to manage the lifecycle of an environment: start, stop, and abort. ```bash bns environments start bns environments stop bns environments abort ``` -------------------------------- ### Go Function Signature Example Source: https://github.com/bunnyshell/cli/blob/master/_autodocs/README.md Illustrates actual function signatures for environment operations, including creating options and retrieving an environment. ```go // Actual function signatures options := environment.NewItemOptions("env-123") env, err := environment.Get(options) ``` -------------------------------- ### Handle Pagination Example Source: https://github.com/bunnyshell/cli/blob/master/_autodocs/api-reference/api-client.md Demonstrates a loop to fetch all items across multiple pages. It continues fetching until the current page number is greater than or equal to the total number of pages. ```go var allItems []*sdk.EnvironmentItem for page := int32(1); ; page++ { options := common.NewListOptions() options.SetPage(page) items, err := environment.List(options) if err != nil { return err } allItems = append(allItems, items.Embedded...) if items.Page >= items.Total { break } } ``` -------------------------------- ### Listing with Pagination Example Source: https://github.com/bunnyshell/cli/blob/master/_autodocs/README.md Shows a pattern for displaying collections of items with pagination support, using a provided function to fetch the data. ```go err := lib.ShowCollection(cmd, options, func() (lib.ModelWithPagination, error) { return environment.List(options) }) ``` -------------------------------- ### Configuration Priority Example Source: https://github.com/bunnyshell/cli/blob/master/_autodocs/configuration.md Demonstrates the priority order for configuration settings, showing how CLI flags override environment variables, which override config file settings. ```bash # Uses JSON from CLI (overrides everything) bns environments list --output json # Uses YAML from environment (overrides config file) export bunnyshell_outputFormat=yaml bns environments list # Uses value from config file bns environments list # Uses default "stylish" rm ~/.bunnyshell/config.yaml bns environments list ``` -------------------------------- ### Query Single Resource Example Source: https://github.com/bunnyshell/cli/blob/master/_autodocs/api-reference/api-client.md Demonstrates how to query a single resource using its ID. Ensure you have the correct options and handle potential errors. ```go options := environment.NewItemOptions("env-123") env, err := environment.Get(options) if err != nil { // Handle error return err } // Use env ``` -------------------------------- ### Define CLI Flags Source: https://github.com/bunnyshell/cli/blob/master/AGENTS.md Examples for handling repeatable, required, and context-aware flags in cobra commands. ```go var statuses []string flags.StringArrayVar(&statuses, "status", statuses, "Filter by status (repeatable)") ``` ```go flags.AddFlag(option.GetRequiredFlag("id")) ``` ```go flags.AddFlag(options.Organization.GetFlag("organization")) ``` -------------------------------- ### Configure Input Prompt with Validation and Defaults Source: https://github.com/bunnyshell/cli/blob/master/_autodocs/api-reference/interactive.md Build a custom input prompt using the Input struct and its methods. This example demonstrates setting a default value, help text, and a custom validation function before asking for a string response. ```go type Input struct { Message string Default string Help string // validator and other fields... } // Methods: // - SetValidate(validator survey.Validator) - Set validation function // - AskString() (string, error) - Prompt and get string response // - With