Skip to content

Commit 0640d63

Browse files
yangshunclaude
andcommitted
Reorder CLI options and docs to match Linux tree categories
Group options into Listing, File, Sorting, Graphics, Output, and Misc categories, matching the section order from the Linux tree(1) man page. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 6892ec7 commit 0640d63

File tree

2 files changed

+66
-46
lines changed

2 files changed

+66
-46
lines changed

README.md

Lines changed: 38 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -59,36 +59,47 @@ Usage:
5959
$ tree <command> [options]
6060
6161
Options:
62+
Listing options:
6263
-a, --all-files All files, including hidden files, are printed.
63-
-D, --date Show last modification time for each entry.
64+
-d, --dirs-only List directories only.
6465
-f, --full-path Print the full path prefix for each file.
65-
-i, --no-indent Print entries without tree indentation lines.
66-
-J, --json Output the tree as a JSON structure.
67-
-p, --permissions Show file type and permissions.
68-
-Q, --quote Quote filenames in double quotes.
66+
-L, --max-depth <n> Max display depth of the directory tree.
67+
-I, --exclude <patterns> Exclude files that match the pattern. | separates
68+
alternate patterns. Wrap your entire pattern in double
69+
quotes. E.g. "node_modules|coverage".
70+
--gitignore Respect .gitignore files (enabled by default).
71+
Use --no-gitignore to disable.
6972
--prune Remove empty directories from output.
70-
--dirs-first List directories before files.
71-
-d, --dirs-only List directories only.
73+
74+
File options:
75+
-Q, --quote Quote filenames in double quotes.
76+
-p, --permissions Show file type and permissions.
7277
-s, --sizes Print the size of each file in bytes along with the name.
7378
--du For each directory report its size as the accumulation
7479
of sizes of all its files and sub-directories. Implies -s.
75-
-I, --exclude <patterns> Exclude files that match the pattern. | separates
76-
alternate patterns. Wrap your entire pattern in double
77-
quotes. E.g. "node_modules|coverage".
78-
-L, --max-depth <n> Max display depth of the directory tree.
79-
-r, --reverse Sort the output in reverse alphabetic order.
80+
-D, --date Show last modification time for each entry.
8081
-F, --trailing-slash Append a '/' for directories.
81-
-S, --line-ascii Turn on ASCII line graphics.
82+
83+
Sorting options:
8284
-v, --version-sort Sort the output by version (natural sort of numbers
8385
within text).
8486
-t, --sort-mtime Sort the output by last modification time.
8587
-c, --sort-ctime Sort the output by last status change time.
8688
-U, --unsorted Do not sort. List files in directory order.
89+
-r, --reverse Sort the output in reverse alphabetic order.
90+
--dirs-first List directories before files.
8791
--files-first List files before directories.
8892
--sort <type> Sort the output by type: name, version, mtime,
8993
ctime, size.
90-
--gitignore Respect .gitignore files (enabled by default).
91-
Use --no-gitignore to disable.
94+
95+
Graphics options:
96+
-i, --no-indent Print entries without tree indentation lines.
97+
-S, --line-ascii Turn on ASCII line graphics.
98+
99+
Output options:
100+
-J, --json Output the tree as a JSON structure.
101+
102+
Misc options:
92103
-h, --help Display this message
93104
--version Display version number
94105
```
@@ -150,25 +161,25 @@ console.log(result);
150161
| Field | Default | Type | Description |
151162
| --------------- | -------------------------- | ---------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
152163
| `allFiles` | `false` | `boolean` | All files, including hidden files, are printed. |
153-
| `date` | `false` | `boolean` | Show last modification time for each entry. |
154-
| `dirsFirst` | `false` | `boolean` | List directories before files. |
164+
| `dirsOnly` | `false` | `boolean` | List directories only. |
155165
| `fullPath` | `false` | `boolean` | Print the full path prefix for each file. |
156-
| `noIndent` | `false` | `boolean` | Print entries without tree indentation lines. |
157-
| `permissions` | `false` | `boolean` | Show file type and permissions (e.g. `[drwxr-xr-x]`). |
158-
| `quote` | `false` | `boolean` | Quote filenames in double quotes. |
166+
| `maxDepth` | `Number.POSITIVE_INFINITY` | `number` | Max display depth of the directory tree. |
167+
| `exclude` | `[]` | `RegExp[]` | An array of regex to test each filename against. Matching files will be excluded and matching directories will not be traversed into. To exclude a directory's contents while still showing the directory itself, use a regex that matches the path with a trailing slash (e.g., `/node_modules\//`). |
168+
| `gitignore` | `true` | `boolean` | Respect `.gitignore` files when inside a git repository. Use `--no-gitignore` to disable. |
159169
| `prune` | `false` | `boolean` | Remove empty directories from output. |
160-
| `dirsOnly` | `false` | `boolean` | List directories only. |
170+
| `quote` | `false` | `boolean` | Quote filenames in double quotes. |
171+
| `permissions` | `false` | `boolean` | Show file type and permissions (e.g. `[drwxr-xr-x]`). |
161172
| `sizes` | `false` | `boolean` | Print the size of each file in bytes along with the name. |
162173
| `du` | `false` | `boolean` | For each directory, report its size as the accumulation of sizes of all its files and sub-directories. Implies `sizes`. |
163-
| `gitignore` | `true` | `boolean` | Respect `.gitignore` files when inside a git repository. Use `--no-gitignore` to disable. |
164-
| `exclude` | `[]` | `RegExp[]` | An array of regex to test each filename against. Matching files will be excluded and matching directories will not be traversed into. To exclude a directory's contents while still showing the directory itself, use a regex that matches the path with a trailing slash (e.g., `/node_modules\//`). |
165-
| `maxDepth` | `Number.POSITIVE_INFINITY` | `number` | Max display depth of the directory tree. |
166-
| `reverse` | `false` | `boolean` | Sort the output in reverse alphabetic order. |
174+
| `date` | `false` | `boolean` | Show last modification time for each entry. |
167175
| `trailingSlash` | `false` | `boolean` | Append a `/` for directories. |
168-
| `lineAscii` | `false` | `boolean` | Turn on ASCII line graphics. |
169-
| `filesFirst` | `false` | `boolean` | List files before directories. |
170176
| `sortBy` | `'name'` | `string` | Sort the output. Options: `'name'`, `'version'`, `'mtime'`, `'ctime'`, `'size'`. |
171177
| `unsorted` | `false` | `boolean` | Do not sort. List files in directory order. |
178+
| `reverse` | `false` | `boolean` | Sort the output in reverse alphabetic order. |
179+
| `dirsFirst` | `false` | `boolean` | List directories before files. |
180+
| `filesFirst` | `false` | `boolean` | List files before directories. |
181+
| `noIndent` | `false` | `boolean` | Print entries without tree indentation lines. |
182+
| `lineAscii` | `false` | `boolean` | Turn on ASCII line graphics. |
172183

173184
## License
174185

src/cli.ts

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,26 @@ const PATTERN_SEPARATOR = '|';
1111

1212
const cli = cac('tree');
1313

14+
// Listing options
1415
cli
1516
.option('-a, --all-files', 'All files, including hidden files, are printed.')
16-
.option('-D, --date', 'Show last modification time for each entry.')
17+
.option('-d, --dirs-only', 'List directories only.')
1718
.option('-f, --full-path', 'Print the full path prefix for each file.')
18-
.option('-i, --no-indent', 'Print entries without tree indentation lines.')
19-
.option('-J, --json', 'Output the tree as a JSON structure.')
20-
.option('-p, --permissions', 'Show file type and permissions.')
21-
.option('-Q, --quote', 'Quote filenames in double quotes.')
19+
.option('-L, --max-depth <n>', 'Max display depth of the directory tree.')
20+
.option(
21+
'-I, --exclude <patterns>',
22+
'Exclude files that match the pattern. | separates alternate patterns. ' +
23+
'Wrap your entire pattern in double quotes. E.g. "node_modules|coverage".',
24+
)
25+
.option(
26+
'--gitignore',
27+
'Respect .gitignore files (enabled by default). Use --no-gitignore to disable.',
28+
)
2229
.option('--prune', 'Remove empty directories from output.')
23-
.option('--dirs-first, --dirsfirst', 'List directories before files.')
24-
.option('-d, --dirs-only', 'List directories only.')
30+
31+
// File options
32+
.option('-Q, --quote', 'Quote filenames in double quotes.')
33+
.option('-p, --permissions', 'Show file type and permissions.')
2534
.option(
2635
'-s, --sizes',
2736
'Print the size of each file in bytes along with the name.',
@@ -30,31 +39,31 @@ cli
3039
'--du',
3140
'For each directory report its size as the accumulation of sizes of all its files and sub-directories. Implies -s.',
3241
)
33-
.option(
34-
'-I, --exclude <patterns>',
35-
'Exclude files that match the pattern. | separates alternate patterns. ' +
36-
'Wrap your entire pattern in double quotes. E.g. "node_modules|coverage".',
37-
)
38-
.option('-L, --max-depth <n>', 'Max display depth of the directory tree.')
39-
.option('-r, --reverse', 'Sort the output in reverse alphabetic order.')
42+
.option('-D, --date', 'Show last modification time for each entry.')
4043
.option('-F, --trailing-slash', "Append a '/' for directories.")
41-
.option('-S, --line-ascii', 'Turn on ASCII line graphics.')
44+
45+
// Sorting options
4246
.option(
4347
'-v, --version-sort',
4448
'Sort the output by version (natural sort of numbers within text).',
4549
)
4650
.option('-t, --sort-mtime', 'Sort the output by last modification time.')
4751
.option('-c, --sort-ctime', 'Sort the output by last status change time.')
4852
.option('-U, --unsorted', 'Do not sort. List files in directory order.')
53+
.option('-r, --reverse', 'Sort the output in reverse alphabetic order.')
54+
.option('--dirs-first, --dirsfirst', 'List directories before files.')
4955
.option('--files-first, --filesfirst', 'List files before directories.')
5056
.option(
5157
'--sort <type>',
5258
'Sort the output by type: name, version, mtime, ctime, size.',
5359
)
54-
.option(
55-
'--gitignore',
56-
'Respect .gitignore files (enabled by default). Use --no-gitignore to disable.',
57-
);
60+
61+
// Graphics options
62+
.option('-i, --no-indent', 'Print entries without tree indentation lines.')
63+
.option('-S, --line-ascii', 'Turn on ASCII line graphics.')
64+
65+
// JSON options
66+
.option('-J, --json', 'Output the tree as a JSON structure.');
5867

5968
cli.help();
6069
cli.version(version, '--version');

0 commit comments

Comments
 (0)