MCPcopy Create free account
hub / github.com/Chat2AnyLLM/code-agent-manager / providerAddFlagMode

Method providerAddFlagMode

internal/cli/provider_cmd.go:255–310  ·  view source on GitHub ↗
(cmd *cobra.Command, state *globalState, name string, flags *addOrUpdateFlags)

Source from the content-addressed store, hash-verified

253}
254
255func (a *App) providerAddFlagMode(cmd *cobra.Command, state *globalState, name string, flags *addOrUpdateFlags) error {
256 if flags.endpoint == "" {
257 return errors.New("--endpoint is required")
258 }
259 if flags.useProxy && flags.noUseProxy {
260 return errors.New("--use-proxy and --no-use-proxy are mutually exclusive")
261 }
262 if flags.keepProxyConfig && flags.noKeepProxy {
263 return errors.New("--keep-proxy-config and --no-keep-proxy-config are mutually exclusive")
264 }
265 if flags.enabled && flags.disabled {
266 return errors.New("--enabled and --disabled are mutually exclusive")
267 }
268
269 input := appapi.ProviderInput{
270 Name: name,
271 Endpoint: flags.endpoint,
272 APIKey: flags.apiKey,
273 APIKeyEnv: flags.apiKeyEnv,
274 ListModelsCmd: flags.listModelsCmd,
275 Description: flags.description,
276 UseProxy: flags.useProxy,
277 KeepProxyConfig: flags.keepProxyConfig,
278 }
279 if flags.clients != "" {
280 _, items, err := parseListFlag(flags.clients, true)
281 if err != nil {
282 return fmt.Errorf("--client: %w", err)
283 }
284 input.Clients = items
285 }
286 if flags.models != "" {
287 _, items, err := parseListFlag(flags.models, true)
288 if err != nil {
289 return fmt.Errorf("--model: %w", err)
290 }
291 input.Models = items
292 }
293 if flags.disabled {
294 v := false
295 input.Enabled = &v
296 } else if flags.enabled {
297 v := true
298 input.Enabled = &v
299 }
300
301 if _, err := providerAPI(state).Add(context.Background(), input); err != nil {
302 if errors.Is(err, providers.ErrAlreadyExists) {
303 return fmt.Errorf("provider %q already exists (use 'cam provider update %s ...' to change it)", name, name)
304 }
305 return err
306 }
307 out := cmd.OutOrStdout()
308 fmt.Fprintf(out, "Added provider %q\n", name)
309 return nil
310}
311
312func (a *App) providerUpdateCommand(state *globalState) *cobra.Command {

Callers 1

providerAddCommandMethod · 0.95

Calls 3

parseListFlagFunction · 0.85
providerAPIFunction · 0.85
AddMethod · 0.45

Tested by

no test coverage detected