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

Function completeMessage

cmd/root/completion.go:57–98  ·  view source on GitHub ↗
(cmd *cobra.Command, args []string, toComplete string)

Source from the content-addressed store, hash-verified

55}
56
57func completeMessage(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
58 if !strings.HasPrefix(toComplete, "/") {
59 return nil, cobra.ShellCompDirectiveNoFileComp
60 }
61
62 agentSource, err := config.Resolve(args[0], nil)
63 if err != nil {
64 return nil, cobra.ShellCompDirectiveNoFileComp
65 }
66
67 cfg, err := config.Load(cmd.Context(), agentSource)
68 if err != nil {
69 return nil, cobra.ShellCompDirectiveNoFileComp
70 }
71
72 agent, _ := cmd.Flags().GetString("agent")
73 if agent == "" {
74 if len(cfg.Agents) == 0 {
75 return nil, cobra.ShellCompDirectiveNoFileComp
76 }
77 // Mirror team.DefaultAgent: prefer "root" when present, otherwise
78 // the first agent declared. This keeps shell completion in sync
79 // with the agent the runtime would actually run.
80 agent = cfg.Agents[0].Name
81 if _, hasRoot := cfg.Agents.Lookup("root"); hasRoot {
82 agent = "root"
83 }
84 }
85 agentCfg, found := cfg.Agents.Lookup(agent)
86 if !found {
87 return nil, cobra.ShellCompDirectiveNoFileComp
88 }
89
90 var candidates []string
91 for k, v := range agentCfg.Commands {
92 if strings.HasPrefix("/"+k, toComplete) {
93 candidates = append(candidates, "/"+k+"\t"+v.DisplayText())
94 }
95 }
96
97 return candidates, cobra.ShellCompDirectiveNoFileComp
98}
99
100func completeTheme(_ *cobra.Command, _ []string, toComplete string) ([]string, cobra.ShellCompDirective) {
101 refs, err := styles.ListThemeRefs()

Callers 1

completeRunExecFunction · 0.85

Calls 5

ResolveFunction · 0.92
LoadFunction · 0.92
ContextMethod · 0.80
DisplayTextMethod · 0.80
LookupMethod · 0.45

Tested by

no test coverage detected