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
├── internal/ # Private application code
│ ├── assets/ # Embedded assets
│ ├── config/ # Configuration management
│ ├── copier/ # Template copying utilities
│ ├── drapi/ # DataRobot API client
│ ├── envbuilder/ # Environment builder
│ ├── misc/ # Miscellaneous utilities
│ ├── repo/ # Repository detection
│ ├── shell/ # Shell utilities
│ ├── task/ # Task discovery and execution
│ ├── tools/ # Tool prerequisites
│ └── version/ # Version information
├── 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.go: The login subcommandcmd/auth/logout.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
An environment configuration builder that:
- Discovers environment variables from templates
- Validates configuration
- Generates
.envfiles - Provides interactive prompts
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:
// 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 the internal/config package:
import "github.com/datarobot/cli/internal/config"
// Get configuration values
apiKey := config.GetAPIKey()
endpoint := config.GetEndpoint()
// Set configuration values
config.SetAPIKey("new-key")
config.SaveConfig()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.