MCPcopy Create free account
hub / github.com/docker/docker-agent / addGatewayFlags

Function addGatewayFlags

cmd/root/flags.go:81–129  ·  view source on GitHub ↗
(cmd *cobra.Command, runConfig *config.RuntimeConfig, loadUserConfig userConfigLoader)

Source from the content-addressed store, hash-verified

79type userConfigLoader func() (*userconfig.Config, error)
80
81func addGatewayFlags(cmd *cobra.Command, runConfig *config.RuntimeConfig, loadUserConfig userConfigLoader) {
82 cmd.PersistentFlags().StringVar(&runConfig.ModelsGateway, flagModelsGateway, "", "Set the models gateway address")
83
84 persistentPreRunE := cmd.PersistentPreRunE
85 cmd.PersistentPreRunE = func(_ *cobra.Command, args []string) error {
86 ctx := cmd.Context()
87
88 // Run any inherited PersistentPreRunE first so directory
89 // overrides (--config-dir, --cache-dir, --data-dir) and other
90 // global setup land before we materialise the env provider —
91 // otherwise the cached provider chain captures a stale config
92 // dir and breaks downstream consumers like the sandbox token
93 // reader.
94 if err := runParentPreRun(cmd, persistentPreRunE, args); err != nil {
95 return err
96 }
97
98 userCfg, err := loadUserConfig()
99 if err != nil {
100 slog.WarnContext(ctx, "Failed to load user config", "error", err)
101 userCfg = &userconfig.Config{}
102 }
103
104 env := runConfig.EnvProvider()
105
106 // Precedence: CLI flag > environment variable > user config
107 if runConfig.ModelsGateway == "" {
108 if gateway, _ := env.Get(ctx, envModelsGateway); gateway != "" {
109 runConfig.ModelsGateway = gateway
110 } else if gateway, _ := env.Get(ctx, cagentEnvModelsGateway); gateway != "" {
111 runConfig.ModelsGateway = gateway
112 } else if userCfg.ModelsGateway != "" {
113 runConfig.ModelsGateway = userCfg.ModelsGateway
114 }
115 }
116 runConfig.ModelsGateway = canonize(runConfig.ModelsGateway)
117
118 // Precedence for default model: environment variable > user config
119 if model, _ := env.Get(ctx, envDefaultModel); model != "" {
120 runConfig.DefaultModel = parseModelShorthand(model)
121 } else if model, _ := env.Get(ctx, cagentEnvDefaultModel); model != "" {
122 runConfig.DefaultModel = parseModelShorthand(model)
123 } else if userCfg.DefaultModel != nil {
124 runConfig.DefaultModel = &userCfg.DefaultModel.ModelConfig
125 }
126
127 return setupWorkingDirectory(runConfig.WorkingDir)
128 }
129}
130
131// runParentPreRun runs the cobra PersistentPreRunE that should fire
132// before this command's own. It first invokes the directly-captured

Calls 7

runParentPreRunFunction · 0.85
canonizeFunction · 0.85
parseModelShorthandFunction · 0.85
setupWorkingDirectoryFunction · 0.85
ContextMethod · 0.80
EnvProviderMethod · 0.80
GetMethod · 0.65