-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Expand file tree
/
Copy pathcli.py
More file actions
36 lines (30 loc) · 935 Bytes
/
cli.py
File metadata and controls
36 lines (30 loc) · 935 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
"""This module provides the RP Tree CLI."""
import argparse
import pathlib
import sys
from . import __version__
from .rptree import DirectoryTree
def main():
args = parse_cmd_line_arguments()
root_dir = pathlib.Path(args.root_dir)
if not root_dir.is_dir():
print("The specified root directory doesn't exist")
sys.exit()
tree = DirectoryTree(root_dir)
tree.generate()
def parse_cmd_line_arguments():
parser = argparse.ArgumentParser(
prog="tree",
description="RP Tree, a directory tree generator",
epilog="Thanks for using RP Tree!",
)
parser.version = f"RP Tree v{__version__}"
parser.add_argument("-v", "--version", action="version")
parser.add_argument(
"root_dir",
metavar="ROOT_DIR",
nargs="?",
default=".",
help="Generate a full directory tree starting at ROOT_DIR",
)
return parser.parse_args()