From 0e5f7feb4b2a0c6a5e6ac1cb7711f9a5db1a613c Mon Sep 17 00:00:00 2001 From: Sebastian Estrella <2049686+sestrella@users.noreply.github.com> Date: Sat, 10 Jan 2026 23:51:18 -0500 Subject: [PATCH] fix(deps): update charmbracelet/huh The `huh` library has been updated, and the way themes are handled has changed. Previously, themes were selected by a string name from a map of functions. Now, themes are directly passed as `*huh.Theme` objects. This commit updates the `rootCmd` to handle the theme selection using the new approach. It also updates the `NewSelectors` function in `selector/root.go` to accept a `huh.Theme` directly. Additionally, the `execCmd`, `logsCmd`, and `updateCmd` have been adjusted to pass the selected theme correctly. --- cmd/exec.go | 2 +- cmd/logs.go | 2 +- cmd/root.go | 60 ++++++++++++++++++++++++------------------------ cmd/update.go | 2 +- selector/root.go | 13 ++--------- 5 files changed, 35 insertions(+), 44 deletions(-) diff --git a/cmd/exec.go b/cmd/exec.go index 21c51a0..03a0165 100644 --- a/cmd/exec.go +++ b/cmd/exec.go @@ -51,7 +51,7 @@ var execCmd = &cobra.Command{ awsClient := client.NewClient(cfg) - selection, err := execSelector(context.TODO(), selector.NewSelectors(awsClient, theme)) + selection, err := execSelector(context.TODO(), selector.NewSelectors(awsClient, *theme)) if err != nil { return err } diff --git a/cmd/logs.go b/cmd/logs.go index 8aa2535..2421e61 100644 --- a/cmd/logs.go +++ b/cmd/logs.go @@ -53,7 +53,7 @@ var logsCmd = &cobra.Command{ client := client.NewClient(cfg) - selection, err := logsSelector(context.TODO(), selector.NewSelectors(client, theme)) + selection, err := logsSelector(context.TODO(), selector.NewSelectors(client, *theme)) if err != nil { return err } diff --git a/cmd/root.go b/cmd/root.go index df09866..e9c405d 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -4,47 +4,47 @@ import ( _ "embed" "fmt" "regexp" - "sort" "strings" - "github.com/sestrella/iecs/selector" + "github.com/charmbracelet/huh" "github.com/spf13/cobra" ) var ( availableThemes string - theme string + themeStr string + theme *huh.Theme + clusterStr string clusterRegex *regexp.Regexp + serviceStr string serviceRegex *regexp.Regexp ) +var themes = map[string]*huh.Theme{ + "base": huh.ThemeBase(), + "base16": huh.ThemeBase16(), + "catppuccin": huh.ThemeCatppuccin(), + "charm": huh.ThemeCharm(), + "dracula": huh.ThemeDracula(), +} + var rootCmd = &cobra.Command{ Use: "iecs", Short: "An interactive CLI for ECS", Long: "Performs commons tasks on ECS, such as getting remote access or viewing logs", PersistentPreRunE: func(cmd *cobra.Command, args []string) error { - if _, ok := selector.Themes[theme]; !ok { - return fmt.Errorf( - "unsupported theme \"%s\" expecting one of: %s", - theme, - availableThemes, - ) + if selectedTheme, ok := themes[themeStr]; ok { + theme = selectedTheme + } else { + return fmt.Errorf("unsupported theme \"%s\" expecting one of: %s", themeStr, availableThemes) } - clusterPattern, err := cmd.Flags().GetString("cluster") - if err != nil { - return err - } - if clusterPattern != "" { - clusterRegex = regexp.MustCompile(clusterPattern) + if clusterStr != "" { + clusterRegex = regexp.MustCompile(clusterStr) } - servicePattern, err := cmd.Flags().GetString("service") - if err != nil { - return err - } - if servicePattern != "" { - serviceRegex = regexp.MustCompile(servicePattern) + if serviceStr != "" { + serviceRegex = regexp.MustCompile(serviceStr) } return nil @@ -53,26 +53,26 @@ var rootCmd = &cobra.Command{ } func Execute(version string) error { - var themeNames []string - for name := range selector.Themes { - themeNames = append(themeNames, fmt.Sprintf("\"%s\"", name)) + themeNames := make([]string, 0, len(themes)) + for name := range themes { + themeNames = append(themeNames, name) } - sort.Strings(themeNames) availableThemes = strings.Join(themeNames, ", ") rootCmd.PersistentFlags(). - StringVarP( - &theme, + StringVar( + &themeStr, "theme", - "t", "charm", fmt.Sprintf( "The theme to use. Available themes are: %s", availableThemes, ), ) - rootCmd.PersistentFlags().String("cluster", "", "A regex pattern for filtering clusters") - rootCmd.PersistentFlags().String("service", "", "A regex pattern for filtering services") + rootCmd.PersistentFlags(). + StringVar(&clusterStr, "cluster", "", "A regex pattern for filtering clusters") + rootCmd.PersistentFlags(). + StringVar(&serviceStr, "service", "", "A regex pattern for filtering services") rootCmd.Version = version if err := rootCmd.Execute(); err != nil { diff --git a/cmd/update.go b/cmd/update.go index e1d4df9..c92cc9e 100644 --- a/cmd/update.go +++ b/cmd/update.go @@ -29,7 +29,7 @@ var updateCmd = &cobra.Command{ } client := client.NewClient(cfg) - selectors := selector.NewSelectors(client, theme) + selectors := selector.NewSelectors(client, *theme) selection, err := updateSelector( context.Background(), diff --git a/selector/root.go b/selector/root.go index c314410..033fe1e 100644 --- a/selector/root.go +++ b/selector/root.go @@ -22,17 +22,8 @@ type Selectors struct { theme huh.Theme } -var Themes = map[string]func() *huh.Theme{ - "base": huh.ThemeBase, - "base16": huh.ThemeBase16, - "catppuccin": huh.ThemeCatppuccin, - "charm": huh.ThemeCharm, - "dracula": huh.ThemeDracula, -} - -func NewSelectors(client client.Client, themeName string) Selectors { - theme := Themes[themeName]() - return Selectors{client: client, theme: *theme} +func NewSelectors(client client.Client, theme huh.Theme) Selectors { + return Selectors{client: client, theme: theme} } func (s Selectors) Cluster(