Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ func init() {
RootCmd.PersistentFlags().Duration("plugin-discovery-timeout", 2*time.Second, "timeout for plugin discovery (0s disables)")
RootCmd.PersistentFlags().Duration("plugin-update-check-interval", internalPlugin.DefaultUpdateCheckInterval, "cooldown between plugin update checks (0s disables)")
RootCmd.PersistentFlags().Bool("skip-plugin-update-check", false, "skip plugin update checks before running plugins")
RootCmd.PersistentFlags().String("locale", "", "locale for plugins (e.g., en, ja)")

// Make some of these flags available via Viper
_ = viper.BindPFlag("config", RootCmd.PersistentFlags().Lookup("config"))
Expand All @@ -116,6 +117,7 @@ func init() {
_ = viper.BindPFlag("plugin-discovery-timeout", RootCmd.PersistentFlags().Lookup("plugin-discovery-timeout"))
_ = viper.BindPFlag("plugin-update-check-interval", RootCmd.PersistentFlags().Lookup("plugin-update-check-interval"))
_ = viper.BindPFlag("skip-plugin-update-check", RootCmd.PersistentFlags().Lookup("skip-plugin-update-check"))
_ = viper.BindPFlag("locale", RootCmd.PersistentFlags().Lookup("locale"))

// Add command groups (plugin group added conditionally by registerPluginCommands)
RootCmd.AddGroup(
Expand Down Expand Up @@ -204,5 +206,3 @@ func initializeConfig(cmd *cobra.Command) error {

return nil
}


2 changes: 2 additions & 0 deletions docs/commands/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ These flags are available for all commands:
--skip-auth Skip authentication checks (for advanced users)
--force-interactive Force the setup wizard to run even if already completed
--all-commands Display all available commands and their flags in tree format
--locale string Locale for plugins (e.g., en, ja)
--plugin-discovery-timeout duration Timeout for plugin discovery (e.g. 2s, 500ms; default: 2s; 0s disables)
-h, --help Show help information
```
Expand Down Expand Up @@ -260,6 +261,7 @@ Global environment variables that affect all commands:
DATAROBOT_ENDPOINT # DataRobot URL
DATAROBOT_API_TOKEN # API token (not recommended)
DATAROBOT_CLI_CONFIG # Path to config file
DATAROBOT_CLI_LOCALE # Locale for plugins (e.g., en, ja)
DATAROBOT_CLI_PLUGIN_DISCOVERY_TIMEOUT # Timeout for plugin discovery (e.g. 2s; 0s disables)
VISUAL # External editor for file editing
EDITOR # External editor for file editing (fallback)
Expand Down
4 changes: 4 additions & 0 deletions docs/development/plugins.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ When `authentication` is enabled:
- Authentication can be bypassed with the global `--skip-auth` flag (for advanced users).
- Your plugin will receive a clean environment with authentication already validated

### Locale

When the user configures a locale via `drconfig.yaml`, the `--locale` flag, or the `DATAROBOT_CLI_LOCALE` environment variable, the CLI passes it to plugins as the `DR_LOCALE` environment variable. Plugins can use this as the highest-priority locale source, falling back to their own detection logic when `DR_LOCALE` is not set.

## Developing a plugin

Minimum requirements:
Expand Down
4 changes: 4 additions & 0 deletions docs/user-guide/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,16 @@ The main configuration file (`drconfig.yaml`) stores your DataRobot connection s
# DataRobot Connection
endpoint: DATA_ROBOT_ENDPOINT_URL # e.g. https://app.datarobot.com
token: API_KEY_HERE

# Optional: locale for plugins (e.g., en, ja)
# locale: ja
```

**Configuration fields:**

- `endpoint`: Your DataRobot instance URL (e.g., `https://app.datarobot.com`)
- `token`: Your API authentication token (automatically stored after `dr auth login`)
- `locale`: Locale for plugins (e.g., `en`, `ja`). When set, passed to plugins as `DR_LOCALE` environment variable.

> [!NOTE]
> You typically don't need to edit this file manually. The CLI manages it automatically when you use `dr auth set-url` and `dr auth login`.
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ require (
github.com/spf13/viper v1.21.0
github.com/stretchr/testify v1.11.1
github.com/ulikunitz/xz v0.5.15
golang.org/x/term v0.36.0
gopkg.in/yaml.v3 v3.0.1
)

Expand Down Expand Up @@ -75,7 +76,6 @@ require (
golang.org/x/exp v0.0.0-20231006140011-7918f672742d // indirect
golang.org/x/net v0.38.0 // indirect
golang.org/x/sys v0.38.0 // indirect
golang.org/x/term v0.36.0 // indirect
golang.org/x/text v0.30.0 // indirect
gopkg.in/mgo.v2 v2.0.0-20190816093944-a6b53ec6cb22 // indirect
)
1 change: 1 addition & 0 deletions internal/config/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ package config
const (
DataRobotURL = "endpoint"
DataRobotAPIKey = "token"
DataRobotLocale = "locale"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we need validation here. If we don't, we should be very explicit about that and this is just passed through.

)
2 changes: 1 addition & 1 deletion internal/drapi/llms.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type LLM struct {
Provider string `json:"provider"`
IsActive bool `json:"isActive"`
Model string `json:"model"`

//Version string `json:"version"`
//Description string `json:"description"`
//Creator string `json:"creator"`
Expand Down
5 changes: 5 additions & 0 deletions internal/plugin/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@ func buildPluginEnv(pluginPath string, requireAuth bool) []string {
env = append(env, "DATAROBOT_CONFIG="+configPath)
}

// Propagate locale setting to plugins when explicitly configured
if locale := viper.GetString(config.DataRobotLocale); locale != "" {
env = append(env, "DR_LOCALE="+locale)
}

if !requireAuth {
return env
}
Expand Down
71 changes: 71 additions & 0 deletions internal/plugin/exec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,3 +187,74 @@ func TestExecutePluginCustomUserAgent(t *testing.T) {

assert.Equal(t, "DataRobot CLI plugin: test-plugin (version 1.2.3)", capturedUserAgent)
}

func TestBuildPluginEnvLocale(t *testing.T) {
tests := []struct {
name string
locale string
expectEnv bool
expectedVal string
}{
{"locale set to ja", "ja", true, "ja"},
{"locale set to en", "en", true, "en"},
{"locale set to ja_JP", "ja_JP", true, "ja_JP"},
{"locale not set", "", false, ""},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
viper.Reset()

if tt.locale != "" {
viper.Set(config.DataRobotLocale, tt.locale)
}

env := buildPluginEnv("/path/to/plugin", false)

found := false

for _, e := range env {
if len(e) > 10 && e[:10] == "DR_LOCALE=" {
found = true

assert.Equal(t, "DR_LOCALE="+tt.expectedVal, e)
}
}

assert.Equal(t, tt.expectEnv, found,
"DR_LOCALE presence mismatch: expected=%v, found=%v", tt.expectEnv, found)
})
}
}

func TestBuildPluginEnvAlwaysSetsPluginMode(t *testing.T) {
viper.Reset()

env := buildPluginEnv("/path/to/plugin", false)

found := false

for _, e := range env {
if e == "DR_PLUGIN_MODE=1" {
found = true
}
}

assert.True(t, found, "DR_PLUGIN_MODE=1 should always be set")
}

func TestBuildPluginEnvSetsPluginPath(t *testing.T) {
viper.Reset()

env := buildPluginEnv("/path/to/my-plugin", false)

found := false

for _, e := range env {
if e == "DR_PLUGIN_PATH=/path/to/my-plugin" {
found = true
}
}

assert.True(t, found, "DR_PLUGIN_PATH should be set to the plugin path")
}
Loading