44 "fmt"
55 "os"
66 "path/filepath"
7+ "strconv"
78
89 "github.com/spf13/pflag"
910 "github.com/spf13/viper"
@@ -13,19 +14,23 @@ type Config struct {
1314 APIURL string `mapstructure:"api_url" yaml:"api_url"`
1415 ConsoleURL string `mapstructure:"console_url" yaml:"console_url"`
1516 GatewayURL string `mapstructure:"gateway_url" yaml:"gateway_url"`
17+ DocsMCP bool `mapstructure:"docs_mcp" yaml:"docs_mcp"`
18+ DocsMCPURL string `mapstructure:"docs_mcp_url" yaml:"docs_mcp_url"`
1619 ProjectID string `mapstructure:"project_id" yaml:"project_id"`
1720 ServiceID string `mapstructure:"service_id" yaml:"service_id"`
1821 Output string `mapstructure:"output" yaml:"output"`
1922 Analytics bool `mapstructure:"analytics" yaml:"analytics"`
2023 PasswordStorage string `mapstructure:"password_storage" yaml:"password_storage"`
21- ConfigDir string `mapstructure:"config_dir" yaml:"-"`
2224 Debug bool `mapstructure:"debug" yaml:"debug"`
25+ ConfigDir string `mapstructure:"config_dir" yaml:"-"`
2326}
2427
2528const (
2629 DefaultAPIURL = "https://console.cloud.timescale.com/public/api/v1"
2730 DefaultConsoleURL = "https://console.cloud.timescale.com"
2831 DefaultGatewayURL = "https://console.cloud.timescale.com/api"
32+ DefaultDocsMCP = true
33+ DefaultDocsMCPURL = "https://mcp.tigerdata.com/docs"
2934 DefaultOutput = "table"
3035 DefaultAnalytics = true
3136 DefaultPasswordStorage = "keyring"
@@ -47,6 +52,8 @@ func SetupViper(configDir string) error {
4752 viper .SetDefault ("api_url" , DefaultAPIURL )
4853 viper .SetDefault ("console_url" , DefaultConsoleURL )
4954 viper .SetDefault ("gateway_url" , DefaultGatewayURL )
55+ viper .SetDefault ("docs_mcp" , DefaultDocsMCP )
56+ viper .SetDefault ("docs_mcp_url" , DefaultDocsMCPURL )
5057 viper .SetDefault ("project_id" , "" )
5158 viper .SetDefault ("service_id" , "" )
5259 viper .SetDefault ("output" , DefaultOutput )
@@ -96,6 +103,8 @@ func (c *Config) Save() error {
96103 viper .Set ("api_url" , c .APIURL )
97104 viper .Set ("console_url" , c .ConsoleURL )
98105 viper .Set ("gateway_url" , c .GatewayURL )
106+ viper .Set ("docs_mcp" , c .DocsMCP )
107+ viper .Set ("docs_mcp_url" , c .DocsMCPURL )
99108 viper .Set ("project_id" , c .ProjectID )
100109 viper .Set ("service_id" , c .ServiceID )
101110 viper .Set ("output" , c .Output )
@@ -118,6 +127,14 @@ func (c *Config) Set(key, value string) error {
118127 c .ConsoleURL = value
119128 case "gateway_url" :
120129 c .GatewayURL = value
130+ case "docs_mcp" :
131+ b , err := setBool ("docs_mcp" , value )
132+ if err != nil {
133+ return err
134+ }
135+ c .DocsMCP = b
136+ case "docs_mcp_url" :
137+ c .DocsMCPURL = value
121138 case "project_id" :
122139 c .ProjectID = value
123140 case "service_id" :
@@ -128,33 +145,37 @@ func (c *Config) Set(key, value string) error {
128145 }
129146 c .Output = value
130147 case "analytics" :
131- if value == "true" {
132- c .Analytics = true
133- } else if value == "false" {
134- c .Analytics = false
135- } else {
136- return fmt .Errorf ("invalid analytics value: %s (must be true or false)" , value )
137- }
138- case "debug" :
139- if value == "true" {
140- c .Debug = true
141- } else if value == "false" {
142- c .Debug = false
143- } else {
144- return fmt .Errorf ("invalid debug value: %s (must be true or false)" , value )
148+ b , err := setBool ("analytics" , value )
149+ if err != nil {
150+ return err
145151 }
152+ c .Analytics = b
146153 case "password_storage" :
147154 if value != "keyring" && value != "pgpass" && value != "none" {
148155 return fmt .Errorf ("invalid password_storage value: %s (must be keyring, pgpass, or none)" , value )
149156 }
150157 c .PasswordStorage = value
158+ case "debug" :
159+ b , err := setBool ("debug" , value )
160+ if err != nil {
161+ return err
162+ }
163+ c .Debug = b
151164 default :
152165 return fmt .Errorf ("unknown configuration key: %s" , key )
153166 }
154167
155168 return c .Save ()
156169}
157170
171+ func setBool (key , val string ) (bool , error ) {
172+ b , err := strconv .ParseBool (val )
173+ if err != nil {
174+ return false , fmt .Errorf ("invalid %s value: %s (must be true or false)" , key , val )
175+ }
176+ return b , nil
177+ }
178+
158179func (c * Config ) Unset (key string ) error {
159180 switch key {
160181 case "api_url" :
@@ -163,6 +184,10 @@ func (c *Config) Unset(key string) error {
163184 c .ConsoleURL = DefaultConsoleURL
164185 case "gateway_url" :
165186 c .GatewayURL = DefaultGatewayURL
187+ case "docs_mcp" :
188+ c .DocsMCP = DefaultDocsMCP
189+ case "docs_mcp_url" :
190+ c .DocsMCPURL = DefaultDocsMCPURL
166191 case "project_id" :
167192 c .ProjectID = ""
168193 case "service_id" :
@@ -171,10 +196,10 @@ func (c *Config) Unset(key string) error {
171196 c .Output = DefaultOutput
172197 case "analytics" :
173198 c .Analytics = DefaultAnalytics
174- case "debug" :
175- c .Debug = DefaultDebug
176199 case "password_storage" :
177200 c .PasswordStorage = DefaultPasswordStorage
201+ case "debug" :
202+ c .Debug = DefaultDebug
178203 default :
179204 return fmt .Errorf ("unknown configuration key: %s" , key )
180205 }
@@ -186,6 +211,8 @@ func (c *Config) Reset() error {
186211 c .APIURL = DefaultAPIURL
187212 c .ConsoleURL = DefaultConsoleURL
188213 c .GatewayURL = DefaultGatewayURL
214+ c .DocsMCP = DefaultDocsMCP
215+ c .DocsMCPURL = DefaultDocsMCPURL
189216 c .ProjectID = ""
190217 c .ServiceID = ""
191218 c .Output = DefaultOutput
0 commit comments