36 lines
1.4 KiB
Python
36 lines
1.4 KiB
Python
import os
|
|
import sys
|
|
import argparse
|
|
from tree_structurer import create_tree_structurer, get_structure
|
|
|
|
def main():
|
|
parser = argparse.ArgumentParser(description='Display directory structure in a tree-like format')
|
|
parser.add_argument('path', nargs='?', default=os.getcwd(),
|
|
help='Path to analyze (default: current directory)')
|
|
parser.add_argument('-v', '--verbose', action='store_true',
|
|
help='Show more detailed output')
|
|
args = parser.parse_args()
|
|
|
|
try:
|
|
if args.verbose:
|
|
print(f"Analyzing directory: {args.path}")
|
|
|
|
create_tree_structurer()
|
|
structure = get_structure(args.path)
|
|
|
|
for line in structure:
|
|
print(line)
|
|
|
|
except Exception as e:
|
|
error_msg = str(e)
|
|
if "Directory does not exist" in error_msg:
|
|
print(f"Error: The specified directory does not exist: {args.path}", file=sys.stderr)
|
|
elif "Directory is empty" in error_msg:
|
|
print(f"Error: The specified directory is empty: {args.path}", file=sys.stderr)
|
|
elif "Path is not a directory" in error_msg:
|
|
print(f"Error: The specified path is not a directory: {args.path}", file=sys.stderr)
|
|
else:
|
|
print(f"Error: {error_msg}", file=sys.stderr)
|
|
sys.exit(1)
|
|
if __name__ == "__main__":
|
|
main() |