memory-bank/components/gitpod-cli.md
The Gitpod CLI (Command Line Interface) is a utility that comes pre-installed within Gitpod workspaces, providing users with a convenient way to interact with the Gitpod platform and control various aspects of their workspace environment from the terminal.
The primary purposes of the Gitpod CLI are:
The Gitpod CLI is implemented as a Go application with a command-based structure using the Cobra command framework. It consists of several key components:
The CLI is designed to be lightweight and efficient, providing a simple interface to the more complex functionality provided by the workspace supervisor.
main.go: Entry point that calls the Execute function from the cmd packagecmd/root.go: Defines the root command and basic CLI configurationcmd/*.go: Individual command implementationspkg/gitpod/: Gitpod-specific functionalitypkg/utils/: Utility functionsThe Gitpod CLI provides a wide range of commands:
gp stop: Stop the current workspacegp snapshot: Take a snapshot of the current workspacegp init: Create a Gitpod configuration for the current projectgp url: Print the URL of the current workspacegp open: Open a file in the IDEgp preview: Open a URL in the IDE's previewgp ports: List all exposed portsgp ports expose: Make a port available on 0.0.0.0gp ports await: Wait for a process to listen on a portgp ports visibility: Set the visibility of a portgp ports protocol: Set the protocol of a portgp tasks: List all tasksgp tasks attach: Attach to a running taskgp tasks stop: Stop a running taskgp env: Manage user-defined environment variablesgp sync-await: Wait for an event to happengp sync-done: Signal that an event has happenedgp credential-helper: Git credential helpergp idp: Identity provider integrationgp timeout: Manage workspace timeoutgp timeout set: Set workspace timeoutgp timeout show: Show workspace timeoutgp timeout extend: Extend workspace timeoutgp info: Show information about the workspacegp user-info: Show information about the usercomponents/supervisor-api/go:lib: Supervisor API definitionscomponents/gitpod-protocol/go:lib: Gitpod protocol definitionscomponents/common-go:lib: Common Go utilitiescomponents/ide-metrics-api/go:lib: IDE metrics API definitionscomponents/public-api/go:lib: Public API definitionsThe Gitpod CLI integrates with:
The CLI implements sophisticated error handling:
The CLI includes analytics tracking to help improve the user experience:
The Gitpod CLI is typically used to:
gp open file.txtgp preview https://example.comgp ports expose 8080gp env NAME=VALUEgp sync-await event && commandgp snapshotgp stop