Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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.
Expand Down
3 changes: 1 addition & 2 deletions cmd/flag.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
30 changes: 28 additions & 2 deletions cmd/root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
Expand All @@ -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)
Expand Down
Loading