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:
- Provide a command-line interface for interacting with Gitpod workspaces
- Enable users to control workspace features and settings
- Facilitate IDE integration from the terminal
- Manage workspace ports and port forwarding
- Control environment variables
- Manage workspace lifecycle
- Coordinate task execution
- Provide authentication and credential management
- Enable workspace snapshots
- Support workspace configuration
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:
- Command Processor: Handles command parsing and execution
- Supervisor Client: Communicates with the workspace supervisor
- Analytics Tracker: Tracks command usage for analytics
- Error Reporter: Reports errors to the supervisor
- Credential Helper: Manages Git credentials
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 functions
The 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 workspace
gp open
: Open a file in the IDEgp preview
: Open a URL in the IDE's preview
gp 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 port
gp tasks
: List all tasksgp tasks attach
: Attach to a running taskgp tasks stop
: Stop a running task
gp env
: Manage user-defined environment variables
gp sync-await
: Wait for an event to happengp sync-done
: Signal that an event has happened
gp credential-helper
: Git credential helpergp idp
: Identity provider integration
gp timeout
: Manage workspace timeoutgp timeout set
: Set workspace timeoutgp timeout show
: Show workspace timeoutgp timeout extend
: Extend workspace timeout
gp info
: Show information about the workspacegp user-info
: Show information about the user
components/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 definitions
- Cobra for command-line interface
- Logrus for logging
- Various Go standard libraries
The Gitpod CLI integrates with:
- Supervisor: Communicates with the workspace supervisor for most operations
- Git: Provides credential helper for Git authentication
- IDE: Opens files and previews in the IDE
- Workspace: Manages workspace lifecycle and configuration
- Identity Providers: Integrates with various identity providers for authentication
The CLI implements sophisticated error handling:
- User-friendly error messages
- Error reporting to the supervisor
- Error logging for debugging
- Different exit codes for different error types
The CLI includes analytics tracking to help improve the user experience:
- Tracks command usage
- Records command outcomes
- Measures command duration
- Reports errors (with user consent)
The Gitpod CLI is typically used to:
- Open files in the IDE:
gp open file.txt
- Preview URLs:
gp preview https://example.com
- Expose ports:
gp ports expose 8080
- Manage environment variables:
gp env NAME=VALUE
- Coordinate task execution:
gp sync-await event && command
- Take workspace snapshots:
gp snapshot
- Stop the workspace:
gp stop
- Supervisor: Provides the API that the CLI uses to interact with the workspace
- IDE: Receives commands from the CLI to open files and previews
- Server: Manages workspace lifecycle and configuration
- Workspace: The environment in which the CLI operates