From ba28eb82526918b7a083ca709cdca95557dc0208 Mon Sep 17 00:00:00 2001 From: Oussama Makhlouk Date: Fri, 15 May 2026 11:47:50 +0100 Subject: [PATCH] issue #58: Improve icon flag naming --- README.md | 5 +++-- cmd/flag.go | 3 +-- cmd/root_test.go | 30 ++++++++++++++++++++++++++++-- 3 files changed, 32 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 4e39cd3..cef17dd 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,8 @@ treels [Flags] [Path] - `-a, --all`: List all files and directories - `-h, --help`: Help for treels - `-t, --tree`: Tree view of the directory -- `-i, --icon`: Disable icons (Enabled by default) +- `--no-icons`: Disable icons +- `-r, --readable`: Show human-readable size for each file and directory ## 📋 Example @@ -49,7 +50,7 @@ This command will display the tree view of the `/Project/treels/` directory. ![](example/example-treels-t.png) ```bash -treels -it /Project/treels +treels -t --no-icons /Project/treels ``` This command will display the tree view without icons of the `/Project/treels/` directory. diff --git a/cmd/flag.go b/cmd/flag.go index 13c7dd2..a79cee9 100644 --- a/cmd/flag.go +++ b/cmd/flag.go @@ -8,9 +8,8 @@ import ( // FlagDefinition func - defines flags for the application. func FlagDefinition(cmd *cobra.Command, flags *module.Flags) { - flags.HideIcon = true cmd.PersistentFlags().BoolVarP(&flags.ShowHidden, "all", "a", false, "List all files and directories") cmd.PersistentFlags().BoolVarP(&flags.ShowTreeView, "tree", "t", false, "Tree view of the directory") - cmd.PersistentFlags().BoolVarP(&flags.HideIcon, "icon", "i", false, "Disable icons (Enabled by default)") + cmd.PersistentFlags().BoolVar(&flags.HideIcon, "no-icons", false, "Disable icons") cmd.PersistentFlags().BoolVarP(&flags.ShowReadableSize, "readable", "r", false, "Show human-readable size for each file and directory") } diff --git a/cmd/root_test.go b/cmd/root_test.go index 6b9798b..73b5635 100644 --- a/cmd/root_test.go +++ b/cmd/root_test.go @@ -32,6 +32,32 @@ func TestRootCmd_TooManyArgs(t *testing.T) { } } +func TestRootCmd_IconFlagsRemoved(t *testing.T) { + tests := []struct { + name string + args []string + want string + }{ + {name: "long flag", args: []string{"--icon"}, want: "unknown flag: --icon"}, + {name: "short flag", args: []string{"-i"}, want: "unknown shorthand flag: 'i'"}, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + cmd := newRootCmd() + cmd.SetArgs(tt.args) + + err := cmd.Execute() + if err == nil { + t.Fatal("Execute() error = nil, want error") + } + if !strings.Contains(err.Error(), tt.want) { + t.Fatalf("Execute() error = %q, want to contain %q", err, tt.want) + } + }) + } +} + func TestRootCmd_ValidPathWithFlags(t *testing.T) { dir := t.TempDir() if err := os.WriteFile(filepath.Join(dir, "main.go"), []byte("package main"), 0o644); err != nil { @@ -40,7 +66,7 @@ func TestRootCmd_ValidPathWithFlags(t *testing.T) { output := captureStdout(t, func() { cmd := newRootCmd() - cmd.SetArgs([]string{"--tree", "--icon", dir}) + cmd.SetArgs([]string{"--tree", "--no-icons", dir}) if err := cmd.Execute(); err != nil { t.Fatalf("Execute() error = %v, want nil", err) @@ -60,7 +86,7 @@ func TestRootCmd_ReadableFlag(t *testing.T) { output := captureStdout(t, func() { cmd := newRootCmd() - cmd.SetArgs([]string{"-r", "--icon", dir}) + cmd.SetArgs([]string{"-r", "--no-icons", dir}) if err := cmd.Execute(); err != nil { t.Fatalf("Execute() error = %v, want nil", err)