Skip to content

Commit 194528a

Browse files
committed
feat: support specific directory to generate
1 parent 3b7c8b7 commit 194528a

2 files changed

Lines changed: 11 additions & 9 deletions

File tree

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,12 @@ Generate a directory structure tree
2020

2121
Options:
2222
-V, --version output the version number
23-
-i, --ignore <ig> ignore specific directory name, separated by comma or '|'
24-
-d, --depth <depth> specify the depth of output
23+
-i, --ignore <ig> ignore specific directory name, separated by comma or '|'
24+
-l, --level <level> specify the level of output
25+
-d, --directory <dir> specify the directory to generate structure tree
2526
-f, --only-folder output folder only
2627
--icon output emoji icon, prefixing filename or directory
27-
-o, --output <output> export content into a file, appending mode by default
28+
-o, --output <output> export content into a file, appending mode by default
2829
-h, --help display help for command
2930
```
3031

src/index.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ program
2020
.version(package.version)
2121
.description('Generate a directory structure tree')
2222
.option('-i, --ignore <ig>', 'ignore specific directory name, separated by comma or \'|\'')
23-
.option('-d, --depth <depth>', 'specify the depth of output')
23+
.option('-l, --level <level>', 'specify the level of output')
24+
.option('-d, --directory <dir>', 'specify the directory to generate structure tree', process.cwd())
2425
.option('-f, --only-folder', 'output folder only')
2526
.option('--icon', 'output emoji icon, prefixing filename or directory')
2627
.option('-o, --output <output>', 'export content into a file, appending mode by default')
@@ -67,15 +68,15 @@ function toTree(path, deep = 0) {
6768
}
6869
}
6970

70-
const root = toTree(process.cwd())
71+
const root = toTree(options.directory)
7172

72-
let depth
73-
if (options.depth && !Number.isNaN(parseInt(options.depth))) {
74-
depth = parseInt(options.depth)
73+
let level
74+
if (options.level && !Number.isNaN(parseInt(options.level))) {
75+
level = parseInt(options.level)
7576
}
7677

7778
function isReachedDepth(deep) {
78-
return typeof depth === 'number' && deep >= depth
79+
return typeof level === 'number' && deep >= level
7980
}
8081

8182
let output = ''

0 commit comments

Comments
 (0)