(cmd *cobra.Command, args []string, toComplete string)
| 55 | } |
| 56 | |
| 57 | func 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 | |
| 100 | func completeTheme(_ *cobra.Command, _ []string, toComplete string) ([]string, cobra.ShellCompDirective) { |
| 101 | refs, err := styles.ListThemeRefs() |
no test coverage detected