From 3a3c2ab68b029ba3d0e9e6d8cffbdb1e63f483f7 Mon Sep 17 00:00:00 2001 From: Michael Lorant Date: Thu, 2 Mar 2023 16:17:47 +1100 Subject: [PATCH] :fire: Remove listing of emoji sets and themes Emoji sets and themes can be displayed within the application. This makes the list command obsolete and can be removed from the application. --- cmd/list.go | 121 ----------------------------- cmd/list_test.go | 100 ------------------------ cmd/root.go | 1 - cmd/testdata/help_arg.golden | 1 - cmd/testdata/help_flag.golden | 1 - cmd/testdata/list_arg.golden | 15 ---- cmd/testdata/list_emoji_arg.golden | 4 - cmd/testdata/list_theme_arg.golden | 8 -- cmd/testdata/root_invalid.golden | 1 - 9 files changed, 252 deletions(-) delete mode 100644 cmd/list.go delete mode 100644 cmd/list_test.go delete mode 100644 cmd/testdata/list_arg.golden delete mode 100644 cmd/testdata/list_emoji_arg.golden delete mode 100644 cmd/testdata/list_theme_arg.golden diff --git a/cmd/list.go b/cmd/list.go deleted file mode 100644 index 2904c70..0000000 --- a/cmd/list.go +++ /dev/null @@ -1,121 +0,0 @@ -package cmd - -import ( - "fmt" - "io" - "strings" - - "github.com/mikelorant/committed/internal/config" - "github.com/mikelorant/committed/internal/emoji" - "github.com/mikelorant/committed/internal/theme" - - "github.com/charmbracelet/lipgloss" - tint "github.com/lrstanley/bubbletint" - "github.com/rodaine/table" - "github.com/spf13/cobra" -) - -func NewListCmd(w io.Writer) *cobra.Command { - cmd := &cobra.Command{ - Use: "list", - Short: "List settings with profiles or IDs", - } - - cmd.AddCommand(NewListThemesCmd(w)) - cmd.AddCommand(NewListEmojiProfilesCmd(w)) - - return cmd -} - -func NewListThemesCmd(w io.Writer) *cobra.Command { - cmd := &cobra.Command{ - Use: "themes", - Short: "List theme IDs", - Args: cobra.NoArgs, - Run: func(cmd *cobra.Command, args []string) { - listThemes(w) - }, - } - - return cmd -} - -func NewListEmojiProfilesCmd(w io.Writer) *cobra.Command { - cmd := &cobra.Command{ - Use: "emojis", - Short: "List emoji profiles", - Args: cobra.NoArgs, - Run: func(cmd *cobra.Command, args []string) { - listEmojiProfiles(w) - }, - } - - return cmd -} - -func listThemes(w io.Writer) { - th := theme.New(config.ColourAdaptive) - - tbl := table.New("Name", "ID", "Palette") - tbl.WithHeaderFormatter(header(th.Registry)) - tbl.WithWidthFunc(lipgloss.Width) - tbl.WithWriter(w) - - for _, v := range th.List() { - th.Set(v.ID()) - tbl.AddRow(v.DisplayName(), v.ID(), palette(th.Registry)) - } - - tbl.Print() -} - -func listEmojiProfiles(w io.Writer) { - em := emoji.New() - th := theme.New(config.ColourAdaptive) - - tbl := table.New("Profile", "URL") - tbl.WithHeaderFormatter(header(th.Registry)) - tbl.WithWidthFunc(lipgloss.Width) - tbl.WithWriter(w) - - for _, v := range em.ListProfiles()[1:] { - tbl.AddRow(emoji.ToString(v), emoji.ToURL(v)) - } - - tbl.Print() -} - -func header(reg *tint.Registry) func(format string, vals ...interface{}) string { - fg := reg.BrightBlack() - if lipgloss.HasDarkBackground() { - fg = reg.BrightWhite() - } - - return func(format string, vals ...interface{}) string { - var ss []any - - for _, v := range vals { - style := lipgloss.NewStyle().Foreground(fg) - ss = append(ss, style.Render(v.(string))) - } - - return fmt.Sprintf(format, ss...) - } -} - -func palette(reg *tint.Registry) string { - var colours []string - - pal := []lipgloss.TerminalColor{ - reg.Black(), reg.Red(), reg.Green(), reg.Yellow(), - reg.Blue(), reg.Purple(), reg.Cyan(), reg.White(), - reg.BrightBlack(), reg.BrightRed(), reg.BrightGreen(), reg.BrightYellow(), - reg.BrightBlue(), reg.BrightPurple(), reg.BrightCyan(), reg.BrightWhite(), - } - - for _, v := range pal { - colours = append(colours, lipgloss.NewStyle().Background(v).Render(" ")) - } - - return strings.Join(colours, "") -} diff --git a/cmd/list_test.go b/cmd/list_test.go deleted file mode 100644 index a40d097..0000000 --- a/cmd/list_test.go +++ /dev/null @@ -1,100 +0,0 @@ -package cmd_test - -import ( - "bytes" - "testing" - - "github.com/mikelorant/committed/cmd" - - "github.com/hexops/autogold/v2" -) - -func TestListCmd(t *testing.T) { - t.Parallel() - - tests := []struct { - name string - }{ - { - name: "list_arg", - }, - } - - for _, tt := range tests { - tt := tt - - t.Run(tt.name, func(t *testing.T) { - t.Parallel() - - var buf bytes.Buffer - - list := cmd.NewListCmd(&buf) - list.SetOut(&buf) - list.SetErr(&buf) - list.SetArgs([]string{}) - - list.Execute() - autogold.ExpectFile(t, autogold.Raw(buf.String()), autogold.Name(tt.name)) - }) - } -} - -func TestListEmojiCmd(t *testing.T) { - t.Parallel() - - tests := []struct { - name string - }{ - { - name: "list_emoji_arg", - }, - } - - for _, tt := range tests { - tt := tt - - t.Run(tt.name, func(t *testing.T) { - t.Parallel() - - var buf bytes.Buffer - - list := cmd.NewListEmojiProfilesCmd(&buf) - list.SetOut(&buf) - list.SetErr(&buf) - list.SetArgs([]string{}) - - list.Execute() - autogold.ExpectFile(t, autogold.Raw(buf.String()), autogold.Name(tt.name)) - }) - } -} - -func TestListThemeCmd(t *testing.T) { - t.Parallel() - - tests := []struct { - name string - }{ - { - name: "list_theme_arg", - }, - } - - for _, tt := range tests { - tt := tt - - t.Run(tt.name, func(t *testing.T) { - t.Parallel() - - var buf bytes.Buffer - - list := cmd.NewListThemesCmd(&buf) - list.SetOut(&buf) - list.SetErr(&buf) - list.SetArgs([]string{}) - - list.Execute() - autogold.ExpectFile(t, autogold.Raw(buf.String()), autogold.Name(tt.name)) - }) - } -} diff --git a/cmd/root.go b/cmd/root.go index 9e016b7..b591ce1 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -74,7 +74,6 @@ func NewRootCmd(a App) *cobra.Command { ) cmd.AddCommand(NewVersionCmd()) - cmd.AddCommand(NewListCmd(a.Writer)) cmd.AddCommand(NewHookCmd(a)) cmd.SetVersionTemplate(verTmpl) cmd.Flags().SortFlags = false diff --git a/cmd/testdata/help_arg.golden b/cmd/testdata/help_arg.golden index ceba089..f771a7b 100644 --- a/cmd/testdata/help_arg.golden +++ b/cmd/testdata/help_arg.golden @@ -8,7 +8,6 @@ Available Commands: completion Generate the autocompletion script for the specified shell help Help about any command hook Install and uninstall Git hook - list List settings with profiles or IDs version Print the version information Flags: diff --git a/cmd/testdata/help_flag.golden b/cmd/testdata/help_flag.golden index ceba089..f771a7b 100644 --- a/cmd/testdata/help_flag.golden +++ b/cmd/testdata/help_flag.golden @@ -8,7 +8,6 @@ Available Commands: completion Generate the autocompletion script for the specified shell help Help about any command hook Install and uninstall Git hook - list List settings with profiles or IDs version Print the version information Flags: diff --git a/cmd/testdata/list_arg.golden b/cmd/testdata/list_arg.golden deleted file mode 100644 index 98166b8..0000000 --- a/cmd/testdata/list_arg.golden +++ /dev/null @@ -1,15 +0,0 @@ -List settings with profiles or IDs - -Usage: - list [command] - -Available Commands: - completion Generate the autocompletion script for the specified shell - emojis List emoji profiles - help Help about any command - themes List theme IDs - -Flags: - -h, --help help for list - -Use "list [command] --help" for more information about a command. diff --git a/cmd/testdata/list_emoji_arg.golden b/cmd/testdata/list_emoji_arg.golden deleted file mode 100644 index f4241eb..0000000 --- a/cmd/testdata/list_emoji_arg.golden +++ /dev/null @@ -1,4 +0,0 @@ -Profile URL -gitmoji https://gitmoji.dev/ -devmoj https://github.com/folke/devmoji -emoji-log https://github.com/ahmadawais/emoji-log diff --git a/cmd/testdata/list_theme_arg.golden b/cmd/testdata/list_theme_arg.golden deleted file mode 100644 index c0919e3..0000000 --- a/cmd/testdata/list_theme_arg.golden +++ /dev/null @@ -1,8 +0,0 @@ -Name ID Palette -Builtin Dark builtin_dark -Dracula dracula -Gruvbox Dark gruvbox_dark -nord nord -Retrowave retrowave -Solarized Dark Higher Contrast solarized_dark_higher_contrast -TokyoNight tokyo_night diff --git a/cmd/testdata/root_invalid.golden b/cmd/testdata/root_invalid.golden index 9803307..cdcd2ba 100644 --- a/cmd/testdata/root_invalid.golden +++ b/cmd/testdata/root_invalid.golden @@ -7,7 +7,6 @@ Available Commands: completion Generate the autocompletion script for the specified shell help Help about any command hook Install and uninstall Git hook - list List settings with profiles or IDs version Print the version information Flags: