This page describes the organization of the DataRobot CLI codebase.
cli/
├── cmd/ # Command implementations (Cobra)
│ ├── root.go # Root command and global flags
│ ├── auth/ # Authentication commands
│ ├── component/ # Component management commands
│ ├── dotenv/ # Environment variable management
│ ├── run/ # Task execution
│ ├── self/ # Self-management commands
│ ├── start/ # Application startup
│ ├── task/ # Task commands
│ ├── templates/ # Template management
│ └── workload/ # Workload lifecycle commands (feature-gated)
├── internal/ # Private application code
│ ├── assets/ # Embedded assets
│ ├── auth/ # Authentication logic (OAuth-style browser flow)
│ ├── cli/ # CLI infrastructure (GatedCommand, etc.)
│ ├── config/ # Configuration management
│ ├── copier/ # Template copying utilities
│ ├── drapi/ # DataRobot API client
│ ├── envbuilder/ # Environment builder
│ ├── features/ # Feature flag system
│ ├── misc/ # Miscellaneous utilities
│ ├── repo/ # Repository detection
│ ├── shell/ # Shell utilities
│ ├── task/ # Task discovery and execution
│ ├── telemetry/ # Anonymous usage analytics (Amplitude)
│ ├── tools/ # Tool prerequisites
│ ├── version/ # Version information
│ └── workload/ # Workload manifest, wizard, deploy, and sync engine
├── tui/ # Terminal UI components
│ ├── banner.go # Banner display
│ ├── interrupt.go # Interrupt handling
│ ├── program.go # TUI execution wrapper
│ └── theme.go # Visual theme
├── docs/ # Documentation
│ ├── commands/ # Command reference
│ ├── development/ # Development guides
│ ├── template-system/ # Template system docs
│ └── user-guide/ # User documentation
├── smoke_test_scripts/ # Smoke tests
├── main.go # Application entry point
├── Taskfile.yaml # Task definitions
├── go.mod # Go module definition
└── goreleaser.yaml # Release configuration
Contains all CLI command implementations using the Cobra framework. Each subdirectory represents a command or command group.
root.gois the root command setup and global flags- Each command has its own subdirectory with
cmd.goas the entry point - Commands that have subcommands are in the same directory
cmd/auth/cmd.go: The auth command groupcmd/auth/login/cmd.go: The login subcommandcmd/auth/logout/cmd.go: The logout subcommand- ...
Private application code that cannot be imported by other projects. This follows Go's convention for internal packages.
The configuration management directory, including:
- Reading/writing configuration files
- Authentication states
- User preferences
DataRobot API client implementation for:
- Template listing and retrieval
- API authentication
- API endpoint communication
See the package doc (go doc ./internal/drapi) for the timeout-override
convention and the HTTPError/errors.As contract new commands should
follow when wiring in a call, or drapi client conventions
for the same content as a dev doc.
OAuth-style browser login flow (auth.EnsureAuthenticated, used as a
PreRunE gate on any command that needs credentials) plus the
credential-verification and interactive URL-picker logic behind
dr auth login/set-url. See
Authentication for the full flow.
Manifest parsing/compilation, the dr workload config setup wizard, the
dr workload up deploy orchestrator, and the code-sync engine behind
dr artifact code sync. A dedicated architecture guide is in review with
the Workload API team; until it lands, internal/workload/*/doc.go (e.g.
go doc ./internal/workload/up) is the best available reference.
An environment configuration builder that:
- Discovers environment variables from templates via
discovery.go - Validates YAML prompt files via
schema.gousing struct-based schema validation - Generates
.envfiles with proper formatting and comments - Provides interactive prompts with conditional logic and auto-generation
Key files:
builder.go: Core prompt types (UserPrompt,PromptOption) and merging logicschema.go: YAML unmarshaling (UnmarshalPromptFile) and validation (PromptFileSchema)discovery.go: Recursive discovery of.datarobotdirectories and prompt filesvalidator.go: Validation rules for environment variablesvalidator_test.go: Comprehensive validation tests
CLI infrastructure and utilities:
CommandAdder: Wraps acobra.Commandand overridesAddCommandto skip children with a disabled feature gate annotation- Used by the root command (and any parent command with gated children) to filter commands at registration time
Feature flag system:
SetGate: Marks a command with a feature gate annotationEnabled: Checks if a feature is enabled via environment variablesAnnotationKey: The key used for feature gate annotations- Environment variable format:
DATAROBOT_CLI_FEATURE_<NAME>(e.g.,DATAROBOT_CLI_FEATURE_WORKLOAD_ALPHA=true)
Task discovery and execution:
- Taskfile detection
- Task parsing
- Task running
- Output handling
Terminal UI components built with Bubble Tea:
- Reusable UI models
- Theme definitions
- Interrupt handling for graceful exits
- Banner displays
Documentation organized by audience:
commands/: Detailed command referencedevelopment/: Development guides for contributorstemplate-system/: Template configuration systemuser-guide/: End-user documentation
Each command follows this pattern:
Note: All top-level commands use singular names (e.g., template, dependency, plugin) for consistency. Plural aliases are available for backward compatibility and should be added when renaming existing commands.
// cmd/example/cmd.go
package example
import "github.com/spf13/cobra"
var Cmd = &cobra.Command{
Use: "example",
Short: "Example command",
Long: `Detailed description`,
PreRunE: func(cmd *cobra.Command, args []string) error {
// Validation and setup
return nil
},
RunE: func(cmd *cobra.Command, args []string) error {
// Command implementation
return nil
},
}
func init() {
// Flag definitions
Cmd.Flags().StringP("flag", "f", "", "Flag description")
}TUI components use the Bubble Tea framework and are executed using the tui.Run wrapper,
which handles Ctrl-C signals and pauses stderr logging (but not .dr-tui-debug.log) while program is running:
// cmd/example/model.go
package example
import (
tea "github.com/charmbracelet/bubbletea"
"github.com/datarobot/cli/tui"
)
type model struct {
// State fields
}
func (m model) Init() tea.Cmd {
return nil
}
func (m model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
// Handle messages
return m, nil
}
func (m model) View() string {
// Render UI
return ""
}
// Usage in command
func runInteractive() error {
m := model{}
_, err := tui.Run(m)
return err
}Configuration is managed through Viper and stored in:
~/.config/datarobot/drconfig.yaml: Global configuration and authentication tokens
Access configuration through internal/config and its viperx wrapper
(the only supported way to read/write viper state — spf13/viper cannot be
imported directly outside internal/config):
import (
"github.com/datarobot/cli/internal/config"
"github.com/datarobot/cli/internal/config/viperx"
)
// Get configuration values
apiKey := viperx.GetString(config.DataRobotAPIKey)
endpoint := config.GetBaseURL()
// Persist a value — only keys listed in config.PersistableKeys are written
viperx.Set(config.DataRobotURL, "https://app.datarobot.com")
config.UpdateConfigFile(config.DataRobotURL)See Configuration for the full contract (persistable keys, env-var binding, redaction rules).
Tests are colocated with the code they test:
- Unit tests:
*_test.gofiles in the same package - Test helpers in same directory when needed
- Smoke tests in the
smoke_test_scripts/directory
Generated files and artifacts:
dist/: Build outputs (created by Task/GoReleaser)tmp/: Temporary build filescoverage.txt: Test coverage reports
- Setup guide: setting up your development environment
- Build guide: Detailed build information and architecture
- Contributing guide—contribution guidelines.