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

Method providerAddCommand

internal/cli/provider_cmd.go:214–253  ·  view source on GitHub ↗
(state *globalState)

Source from the content-addressed store, hash-verified

212}
213
214func (a *App) providerAddCommand(state *globalState) *cobra.Command {
215 flags := &addOrUpdateFlags{}
216 cmd := &cobra.Command{
217 Use: "add [NAME] [--endpoint URL] [flags]",
218 Short: "Add a new provider (interactive wizard when flags omitted)",
219 Args: cobra.RangeArgs(0, 1),
220 RunE: func(cmd *cobra.Command, args []string) error {
221 name := ""
222 if len(args) > 0 {
223 name = args[0]
224 }
225 if name != "" && cmd.Flags().Changed("endpoint") {
226 return a.providerAddFlagMode(cmd, state, name, flags)
227 }
228 listed, err := providerAPI(state).List(context.Background())
229 if err != nil {
230 return err
231 }
232 existingNames := providersFileFromAPI(listed).SortedNames()
233 name, ep, cancelled, err := runProviderWizard(cmd.OutOrStdout(), cmd.InOrStdin(), wizardModeAdd, nil, "", existingNames)
234 if err != nil {
235 return err
236 }
237 if cancelled {
238 return nil
239 }
240 if _, err := providerAPI(state).Add(context.Background(), providerInputFromEndpoint(name, ep)); err != nil {
241 if errors.Is(err, providers.ErrAlreadyExists) {
242 return fmt.Errorf("provider %q already exists (use 'cam provider update %s ...' to change it)", name, name)
243 }
244 return err
245 }
246 out := cmd.OutOrStdout()
247 fmt.Fprintf(out, "Added provider %q\n", name)
248 return nil
249 },
250 }
251 bindAddOrUpdateFlags(cmd, flags)
252 return cmd
253}
254
255func (a *App) providerAddFlagMode(cmd *cobra.Command, state *globalState, name string, flags *addOrUpdateFlags) error {
256 if flags.endpoint == "" {

Callers 1

providerCommandMethod · 0.95

Calls 9

providerAddFlagModeMethod · 0.95
providerAPIFunction · 0.85
providersFileFromAPIFunction · 0.85
runProviderWizardFunction · 0.85
bindAddOrUpdateFlagsFunction · 0.85
SortedNamesMethod · 0.80
ListMethod · 0.45
AddMethod · 0.45

Tested by

no test coverage detected