package cmd import ( "fmt" "os" "parts-cli/internal/client" "github.com/spf13/cobra" "github.com/spf13/viper" ) var rootCmd = &cobra.Command{ Use: "parts", Short: "CLI for the parts inventory API", } // Execute runs the root command. func Execute() { if err := rootCmd.Execute(); err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(1) } } func init() { cobra.OnInitialize(initConfig) } func initConfig() { viper.SetConfigName(".parts-inventory") viper.SetConfigType("yaml") viper.AddConfigPath("$HOME") home, err := os.UserHomeDir() if err == nil { viper.AddConfigPath(home) } viper.SetEnvPrefix("") viper.BindEnv("api_url", "PARTS_API_URL") //nolint:errcheck viper.SetDefault("api_url", "http://localhost:3001") _ = viper.ReadInConfig() } // GetClient returns a configured API client. func GetClient() *client.Client { return client.New(viper.GetString("api_url")) }