Skip to content

Commit 60b98c2

Browse files
yangshunclaude
andcommitted
Add -v flag for version/natural sort of directory entries
Implements natural sorting (numeric-aware) matching Linux tree's -v flag. The --version flag (without -v short alias) is now used to display the version number. Closes #20 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 5eb6bb8 commit 60b98c2

10 files changed

Lines changed: 197 additions & 45 deletions

File tree

‎README.md‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,10 @@ Options:
7070
-r, --reverse Sort the output in reverse alphabetic order.
7171
-F, --trailing-slash Append a '/' for directories.
7272
-S, --line-ascii Turn on ASCII line graphics.
73+
-v, --version-sort Sort the output by version (natural sort of numbers
74+
within text).
7375
-h, --help Display this message
74-
-v, --version Display version number
76+
--version Display version number
7577
```
7678

7779
## Node.js API
@@ -95,6 +97,7 @@ const string = tree('path/to/dir', options);
9597
| `reverse` | `false` | `boolean` | Sort the output in reverse alphabetic order. |
9698
| `trailingSlash` | `false` | `boolean` | Appends a trailing slash behind directories. |
9799
| `lineAscii` | `false` | `boolean` | Turn on ASCII line graphics. |
100+
| `versionSort` | `false` | `boolean` | Sort the output by version (natural sort of numbers within text). |
98101

99102
```js
100103
import tree from 'tree-node-cli';

‎src/__tests__/__fixtures__/numbered-files/file1.txt‎

Whitespace-only changes.

‎src/__tests__/__fixtures__/numbered-files/file10.txt‎

Whitespace-only changes.

‎src/__tests__/__fixtures__/numbered-files/file2.txt‎

Whitespace-only changes.

‎src/__tests__/__fixtures__/numbered-files/file20.txt‎

Whitespace-only changes.

‎src/__tests__/__fixtures__/numbered-files/file3.txt‎

Whitespace-only changes.

0 commit comments

Comments
 (0)