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

Method providerListCommand

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

Source from the content-addressed store, hash-verified

58}
59
60func (a *App) providerListCommand(state *globalState) *cobra.Command {
61 var asJSON bool
62 var enabledOnly bool
63 cmd := &cobra.Command{
64 Use: "list",
65 Short: "List configured providers",
66 Args: cobra.NoArgs,
67 RunE: func(cmd *cobra.Command, _ []string) error {
68 listed, err := providerAPI(state).List(context.Background())
69 if err != nil {
70 return err
71 }
72 out := cmd.OutOrStdout()
73 file := providersFileFromAPI(listed)
74 names := file.SortedNames()
75 filtered := make([]string, 0, len(names))
76 for _, n := range names {
77 if enabledOnly && !file.Endpoints[n].IsEnabled() {
78 continue
79 }
80 filtered = append(filtered, n)
81 }
82 if asJSON {
83 subset := map[string]providers.Endpoint{}
84 for _, n := range filtered {
85 subset[n] = file.Endpoints[n]
86 }
87 return writeJSON(out, subset)
88 }
89 if len(filtered) == 0 {
90 fmt.Fprintf(out, "No providers configured. Add one with 'cam provider add NAME --endpoint URL'.\n")
91 return nil
92 }
93 writeProviderTable(out, file, filtered)
94 return nil
95 },
96 }
97 cmd.Flags().BoolVar(&asJSON, "json", false, "Emit JSON instead of a table")
98 cmd.Flags().BoolVar(&enabledOnly, "enabled-only", false, "Skip disabled providers")
99 return cmd
100}
101
102func writeProviderTable(out io.Writer, file providers.File, names []string) {
103 nameWidth := len("NAME")

Callers 1

providerCommandMethod · 0.95

Calls 7

providerAPIFunction · 0.85
providersFileFromAPIFunction · 0.85
writeProviderTableFunction · 0.85
SortedNamesMethod · 0.80
writeJSONFunction · 0.70
ListMethod · 0.45
IsEnabledMethod · 0.45

Tested by

no test coverage detected