Skip to content
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,6 @@ func buildRootCmd() *cobra.Command {
// Declare ALL flag variables locally within this function
var configDir string
var debug bool
var output string
var projectID string
var serviceID string
var analytics bool
Expand All @@ -429,15 +428,13 @@ func buildRootCmd() *cobra.Command {
cobra.OnInitialize(initConfigFunc)
cmd.PersistentFlags().StringVar(&configDir, "config-dir", config.GetDefaultConfigDir(), "config directory")
cmd.PersistentFlags().BoolVar(&debug, "debug", false, "enable debug logging")
cmd.PersistentFlags().VarP((*outputFlag)(&output), "output", "o", "output format (json, yaml, table)")
cmd.PersistentFlags().StringVar(&projectID, "project-id", "", "project ID")
cmd.PersistentFlags().StringVar(&serviceID, "service-id", "", "service ID")
cmd.PersistentFlags().BoolVar(&analytics, "analytics", true, "enable/disable usage analytics")
cmd.PersistentFlags().StringVar(&passwordStorage, "password-storage", config.DefaultPasswordStorage, "password storage method (keyring, pgpass, none)")

// Bind flags to viper
viper.BindPFlag("debug", cmd.PersistentFlags().Lookup("debug"))
viper.BindPFlag("output", cmd.PersistentFlags().Lookup("output"))
// ... bind remaining flags

// Add all subcommands (complete tree building)
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,6 @@ These flags are available on all commands and take precedence over both environm
- `--config-dir <path>` - Path to configuration directory (default: `~/.config/tiger`)
- `--project-id <id>` - Specify project ID
- `--service-id <id>` - Specify service ID
- `-o, --output <format>` - Output format: `json`, `yaml`, or `table`
- `--analytics` - Enable/disable analytics
- `--password-storage <method>` - Password storage method: `keyring`, `pgpass`, or `none`
- `--debug` - Enable/disable debug logging
Expand Down
144 changes: 88 additions & 56 deletions internal/tiger/cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import (
"encoding/json"
"fmt"

"github.com/olekukonko/tablewriter"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"go.uber.org/zap"
"gopkg.in/yaml.v3"

Expand All @@ -13,7 +15,11 @@ import (
)

func buildConfigShowCmd() *cobra.Command {
return &cobra.Command{
var output string
var noDefaults bool
var withEnv bool

cmd := &cobra.Command{
Use: "show",
Short: "Show current configuration",
Long: `Display the current CLI configuration settings`,
Expand All @@ -26,7 +32,40 @@ func buildConfigShowCmd() *cobra.Command {
return fmt.Errorf("failed to load config: %w", err)
}

switch cfg.Output {
// Use flag value if provided, otherwise use config value
outputFormat := cfg.Output
if cmd.Flags().Changed("output") {
outputFormat = output
}

configFile, err := cfg.EnsureConfigDir()
if err != nil {
return err
}

// a new viper, free from env and cli flags
v := viper.New()
v.SetConfigFile(configFile)
if withEnv {
config.ApplyEnvOverrides(v)
}
if !noDefaults {
config.ApplyDefaults(v)
}
if err := config.ReadInConfig(v); err != nil {
return err
}

cfg, err = config.FromViper(v)
if err != nil {
return err
}

if cfg.ConfigDir == config.GetDefaultConfigDir() {
cfg.ConfigDir = ""
}

switch outputFormat {
case "json":
return outputJSON(cfg, cmd)
case "yaml":
Expand All @@ -36,6 +75,12 @@ func buildConfigShowCmd() *cobra.Command {
}
},
}

cmd.Flags().VarP((*outputFlag)(&output), "output", "o", "output format (json, yaml, table)")
cmd.Flags().BoolVar(&noDefaults, "no-defaults", false, "do not show default values for unset fields")
cmd.Flags().BoolVar(&withEnv, "with-env", false, "apply environment variable overrides")

return cmd
}

func buildConfigSetCmd() *cobra.Command {
Expand Down Expand Up @@ -133,68 +178,55 @@ func buildConfigCmd() *cobra.Command {
}

func outputTable(cfg *config.Config, cmd *cobra.Command) error {
out := cmd.OutOrStdout()
fmt.Fprintln(out, "Current Configuration:")
fmt.Fprintf(out, " api_url: %s\n", cfg.APIURL)
fmt.Fprintf(out, " console_url: %s\n", cfg.ConsoleURL)
fmt.Fprintf(out, " gateway_url: %s\n", cfg.GatewayURL)
fmt.Fprintf(out, " docs_mcp: %t\n", cfg.DocsMCP)
fmt.Fprintf(out, " docs_mcp_url: %s\n", cfg.DocsMCPURL)
fmt.Fprintf(out, " project_id: %s\n", valueOrEmpty(cfg.ProjectID))
fmt.Fprintf(out, " service_id: %s\n", valueOrEmpty(cfg.ServiceID))
fmt.Fprintf(out, " output: %s\n", cfg.Output)
fmt.Fprintf(out, " analytics: %t\n", cfg.Analytics)
fmt.Fprintf(out, " password_storage: %s\n", cfg.PasswordStorage)
fmt.Fprintf(out, " debug: %t\n", cfg.Debug)
fmt.Fprintf(out, " config_dir: %s\n", cfg.ConfigDir)
return nil
table := tablewriter.NewWriter(cmd.OutOrStdout())
table.Header("PROPERTY", "VALUE")
if cfg.APIURL != "" {
table.Append("api_url", cfg.APIURL)
}
if cfg.ConsoleURL != "" {
table.Append("console_url", cfg.ConsoleURL)
}
if cfg.GatewayURL != "" {
table.Append("gateway_url", cfg.GatewayURL)
}
if cfg.DocsMCP {
table.Append("docs_mcp", fmt.Sprintf("%t", cfg.DocsMCP))
}
if cfg.DocsMCPURL != "" {
table.Append("docs_mcp_url", cfg.DocsMCPURL)
}
if cfg.ProjectID != "" {
table.Append("project_id", cfg.ProjectID)
}
if cfg.ServiceID != "" {
table.Append("service_id", cfg.ServiceID)
}
if cfg.Output != "" {
table.Append("output", cfg.Output)
}
if cfg.Analytics {
table.Append("analytics", fmt.Sprintf("%t", cfg.Analytics))
}
if cfg.PasswordStorage != "" {
table.Append("password_storage", cfg.PasswordStorage)
}
if cfg.Debug {
table.Append("debug", fmt.Sprintf("%t", cfg.Debug))
}
if cfg.ConfigDir != "" {
table.Append("config_dir", cfg.ConfigDir)
}
return table.Render()
}

func outputJSON(cfg *config.Config, cmd *cobra.Command) error {
data := map[string]interface{}{
"api_url": cfg.APIURL,
"console_url": cfg.ConsoleURL,
"gateway_url": cfg.GatewayURL,
"docs_mcp": cfg.DocsMCP,
"docs_mcp_url": cfg.DocsMCPURL,
"project_id": cfg.ProjectID,
"service_id": cfg.ServiceID,
"output": cfg.Output,
"analytics": cfg.Analytics,
"password_storage": cfg.PasswordStorage,
"debug": cfg.Debug,
"config_dir": cfg.ConfigDir,
}

encoder := json.NewEncoder(cmd.OutOrStdout())
encoder.SetIndent("", " ")
return encoder.Encode(data)
return encoder.Encode(cfg)
}

func outputYAML(cfg *config.Config, cmd *cobra.Command) error {
data := map[string]interface{}{
"api_url": cfg.APIURL,
"console_url": cfg.ConsoleURL,
"gateway_url": cfg.GatewayURL,
"docs_mcp": cfg.DocsMCP,
"docs_mcp_url": cfg.DocsMCPURL,
"project_id": cfg.ProjectID,
"service_id": cfg.ServiceID,
"output": cfg.Output,
"analytics": cfg.Analytics,
"password_storage": cfg.PasswordStorage,
"debug": cfg.Debug,
"config_dir": cfg.ConfigDir,
}

encoder := yaml.NewEncoder(cmd.OutOrStdout())
defer encoder.Close()
return encoder.Encode(data)
}

func valueOrEmpty(s string) string {
if s == "" {
return "(not set)"
}
return s
return encoder.Encode(cfg)
}
Loading