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
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ treels # compact ls-style view
treels -t # tree view
treels -t --depth 2 # tree view, limited to two levels
treels -t --gitignore # tree view, excluding .gitignore matches
treels --no-summary # hide the final count line
```

> [!NOTE]
Expand Down Expand Up @@ -158,6 +159,12 @@ Disable icons:
treels --no-icons
```

Hide the final summary:

```bash
treels --no-summary
```

## Flags

| Flag | Description |
Expand All @@ -167,6 +174,7 @@ treels --no-icons
| `--depth N` | Limit tree recursion depth. |
| `--gitignore` | Respect `.gitignore` rules from the target directory. |
| `--no-icons` | Disable file and folder icons. |
| `--no-summary` | Hide the final file and directory count. |
| `-r`, `--readable` | Show human-readable file and directory sizes. |
| `-v`, `--version` | Print the current version. |
| `-h`, `--help` | Show help. |
Expand Down
1 change: 1 addition & 0 deletions cmd/flag.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ func FlagDefinition(cmd *cobra.Command, flags *module.Flags) {
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().BoolVar(&flags.HideIcon, "no-icons", false, "Disable icons")
cmd.PersistentFlags().BoolVar(&flags.HideSummary, "no-summary", false, "Hide the final file and directory count")
cmd.PersistentFlags().BoolVar(&flags.RespectGitIgnore, "gitignore", false, "Respect .gitignore rules")
cmd.PersistentFlags().IntVar(&flags.TreeDepth, "depth", -1, "Limit tree view recursion depth")
cmd.PersistentFlags().Lookup("depth").DefValue = "unlimited"
Expand Down
23 changes: 23 additions & 0 deletions cmd/root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,29 @@ func TestRootCmd_DepthFlagRejectsNegativeValue(t *testing.T) {
}
}

func TestRootCmd_NoSummaryFlag(t *testing.T) {
dir := t.TempDir()
if err := os.WriteFile(filepath.Join(dir, "main.go"), []byte("package main"), 0o644); err != nil {
t.Fatalf("WriteFile() error = %v", err)
}

output := captureStdout(t, func() {
cmd := newRootCmd()
cmd.SetArgs([]string{"--no-summary", "--no-icons", dir})

if err := cmd.Execute(); err != nil {
t.Fatalf("Execute() error = %v, want nil", err)
}
})

if !strings.Contains(output, "main.go") {
t.Fatalf("Execute() output = %q, want visible file", output)
}
if strings.Contains(output, "directories,") {
t.Fatalf("Execute() output = %q, want no summary", output)
}
}

func TestRootCmd_GitIgnoreFlag(t *testing.T) {
dir := t.TempDir()
if err := os.WriteFile(filepath.Join(dir, ".gitignore"), []byte("ignored.txt\n"), 0o644); err != nil {
Expand Down
1 change: 1 addition & 0 deletions module/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ type Flags struct {
HideIcon bool
ShowReadableSize bool
ShowVersion bool
HideSummary bool
RespectGitIgnore bool
TreeDepth int
LimitTreeDepth bool
Expand Down
4 changes: 4 additions & 0 deletions service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ func dispatcher(options module.Options, output io.Writer) error {
return err
}
}
if options.Flags.HideSummary {
return nil
}

return printNumberOfFilesAndDirectories(output, fileCount, dirCount)
}

Expand Down
40 changes: 40 additions & 0 deletions service/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,46 @@ func TestDispatcher_TreeDirectoryDepth(t *testing.T) {
}
}

func TestDispatcher_NoSummary(t *testing.T) {
dir := t.TempDir()
mustMkdir(t, filepath.Join(dir, "subpkg"))
mustWriteFile(t, filepath.Join(dir, "main.go"), "package main")

tests := []struct {
name string
flags module.Flags
}{
{
name: "flat mode",
flags: module.Flags{HideIcon: true, HideSummary: true},
},
{
name: "tree mode",
flags: module.Flags{HideIcon: true, HideSummary: true, ShowTreeView: true},
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
var output bytes.Buffer
err := dispatcher(module.Options{Directory: dir, Flags: tt.flags}, &output)
if err != nil {
t.Fatalf("dispatcher() error = %v, want nil", err)
}

got := stripANSI(output.String())
for _, want := range []string{".", "main.go", "subpkg"} {
if !strings.Contains(got, want) {
t.Fatalf("dispatcher() output = %q, want to contain %q", got, want)
}
}
if strings.Contains(got, "directories,") {
t.Fatalf("dispatcher() output = %q, want no summary", got)
}
})
}
}

func TestDispatcher_ListDirectoryGitIgnore(t *testing.T) {
dir := t.TempDir()
mustWriteFile(t, filepath.Join(dir, ".gitignore"), "*.log\nignored-dir/\n!keep.log\n")
Expand Down
Loading