MCPcopy
hub / github.com/docker/docker-agent / runAliasListCommand

Function runAliasListCommand

cmd/root/alias.go:211–285  ·  view source on GitHub ↗
(cmd *cobra.Command, args []string, asJSON bool)

Source from the content-addressed store, hash-verified

209}
210
211func runAliasListCommand(cmd *cobra.Command, args []string, asJSON bool) (commandErr error) {
212 telemetry.TrackCommand(cmd.Context(), "alias", append([]string{"list"}, args...))
213 defer func() { // do not inline this defer so that commandErr is not resolved early
214 telemetry.TrackCommandError(cmd.Context(), "alias", append([]string{"list"}, args...), commandErr)
215 }()
216
217 out := cli.NewPrinter(cmd.OutOrStdout())
218
219 cfg, err := userconfig.Load()
220 if err != nil {
221 return fmt.Errorf("failed to load config: %w", err)
222 }
223
224 allAliases := cfg.Aliases
225
226 // Sort aliases by name for consistent output
227 names := slices.Sorted(maps.Keys(allAliases))
228
229 if asJSON {
230 entries := make([]aliasListEntry, 0, len(names))
231 for _, name := range names {
232 entries = append(entries, aliasListEntry{Name: name, Alias: *allAliases[name]})
233 }
234 encoded, err := json.MarshalIndent(entries, "", " ")
235 if err != nil {
236 return fmt.Errorf("failed to encode aliases as JSON: %w", err)
237 }
238 out.Println(string(encoded))
239 return nil
240 }
241
242 if len(allAliases) == 0 {
243 out.Println("No aliases registered.")
244 out.Println("\nCreate an alias with: docker agent alias add <name> <agent-path>")
245 return nil
246 }
247
248 out.Printf("Registered aliases (%d):\n\n", len(allAliases))
249
250 // Find max name width for alignment (using display width for proper Unicode handling)
251 maxLen := 0
252 for _, name := range names {
253 maxLen = max(maxLen, runewidth.StringWidth(name))
254 }
255
256 for _, name := range names {
257 alias := allAliases[name]
258 padding := strings.Repeat(" ", maxLen-runewidth.StringWidth(name))
259
260 // Build options string
261 var options []string
262 if alias.Yolo {
263 options = append(options, "yolo")
264 }
265 if alias.Model != "" {
266 options = append(options, "model="+alias.Model)
267 }
268 if alias.HideToolResults {

Calls 8

PrintlnMethod · 0.95
PrintfMethod · 0.95
TrackCommandFunction · 0.92
TrackCommandErrorFunction · 0.92
NewPrinterFunction · 0.92
LoadFunction · 0.92
ContextMethod · 0.80
KeysMethod · 0.45