Skip to content

Commit d1cd73c

Browse files
Merge pull request #635 from bartlettroscoe/tree-exclude
Add --exclude option
2 parents 7245975 + 3f44529 commit d1cd73c

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

tribits/python_utils/tree.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ def tree(dir, padding, options, depth, top_level=False):
2222
else:
2323
depth = depth - 1
2424

25+
dir_basename = basename(abspath(dir))
26+
27+
if options.exclude and options.exclude == dir_basename:
28+
return
29+
2530
print_files = options.printFiles
2631
print_compact = options.printCompact
2732

@@ -31,12 +36,12 @@ def tree(dir, padding, options, depth, top_level=False):
3136
else:
3237
verticalLineChar = '|'
3338
fileDirPrefix = '+-'
34-
39+
3540
init_prefix = padding[:-1]
3641
if top_level: init_prefix += ' '
3742
else: init_prefix += fileDirPrefix
3843

39-
print(init_prefix + basename(abspath(dir)) + '/')
44+
print(init_prefix + dir_basename + '/')
4045

4146
padding = padding + ' '
4247

@@ -95,7 +100,11 @@ def main():
95100
clp.add_option(
96101
"--depth", dest="depth", type="int", default=None,
97102
help="Depth (integer) to recurse into. Default = '' or unbounded.")
98-
103+
104+
clp.add_option(
105+
"--exclude", dest="exclude", type="string", default=None,
106+
help="Exclude matching directory or file (e.g. '.git').")
107+
99108
(options, args) = clp.parse_args()
100109

101110
if len(args) != 1:

0 commit comments

Comments
 (0)