setWebSearchProvider validates the name and applies it via env var for this process. For persistence, the user sets it in their shell or .env.
(name string)
| 121 | // setWebSearchProvider validates the name and applies it via env var for |
| 122 | // this process. For persistence, the user sets it in their shell or .env. |
| 123 | func (cli *ChatCLI) setWebSearchProvider(name string) { |
| 124 | name = strings.ToLower(strings.TrimSpace(name)) |
| 125 | |
| 126 | valid := map[string]bool{ |
| 127 | string(plugins.ProviderAuto): true, |
| 128 | string(plugins.ProviderSearXNG): true, |
| 129 | string(plugins.ProviderDuckDuckGo): true, |
| 130 | string(plugins.ProviderBrave): true, |
| 131 | string(plugins.ProviderMojeek): true, |
| 132 | } |
| 133 | if !valid[name] { |
| 134 | fmt.Println(colorize(" "+i18n.T("ws.cmd.invalid_provider", name), ColorYellow)) |
| 135 | fmt.Println(colorize(" "+i18n.T("ws.cmd.valid_options"), ColorGray)) |
| 136 | return |
| 137 | } |
| 138 | |
| 139 | if name == string(plugins.ProviderAuto) { |
| 140 | _ = os.Unsetenv("CHATCLI_WEBSEARCH_PROVIDER") |
| 141 | } else { |
| 142 | _ = os.Setenv("CHATCLI_WEBSEARCH_PROVIDER", name) |
| 143 | } |
| 144 | |
| 145 | if name == string(plugins.ProviderSearXNG) && os.Getenv("SEARXNG_URL") == "" { |
| 146 | fmt.Println(colorize(" "+i18n.T("ws.cmd.sx_missing_url_warn"), ColorYellow)) |
| 147 | fmt.Println(colorize(" "+i18n.T("ws.cmd.sx_missing_url_hint1"), ColorGray)) |
| 148 | fmt.Println(colorize(" "+i18n.T("ws.cmd.sx_missing_url_hint2"), ColorGray)) |
| 149 | } |
| 150 | |
| 151 | fmt.Println(colorize(" "+i18n.T("ws.cmd.provider_set_session", name), ColorGreen)) |
| 152 | fmt.Println(colorize(" "+i18n.T("ws.cmd.persist_hint"), ColorGray)) |
| 153 | if name == string(plugins.ProviderAuto) { |
| 154 | fmt.Println(colorize(" "+i18n.T("ws.cmd.persist_unset"), ColorGray)) |
| 155 | } else { |
| 156 | fmt.Println(colorize(" "+i18n.T("ws.cmd.persist_set", name), ColorGray)) |
| 157 | } |
| 158 | cli.showWebSearchStatus() |
| 159 | } |
no test coverage detected