|
1 |
| -"""This module provides RP Tree cli.""" |
| 1 | +"""This module provides the RP Tree CLI.""" |
2 | 2 |
|
3 | 3 | import argparse
|
4 | 4 | import pathlib
|
|
11 | 11 | def main():
|
12 | 12 | args = parse_cmd_line_arguments()
|
13 | 13 | root_dir = pathlib.Path(args.root_dir)
|
14 |
| - |
15 | 14 | if not root_dir.is_dir():
|
16 | 15 | print("The specified root directory doesn't exist")
|
17 | 16 | sys.exit()
|
18 |
| - |
19 |
| - tree = DirectoryTree(root_dir, args.output_file, args.dir_only) |
| 17 | + tree = DirectoryTree( |
| 18 | + root_dir, dir_only=args.dir_only, output_file=args.output_file |
| 19 | + ) |
20 | 20 | tree.generate()
|
21 | 21 |
|
22 | 22 |
|
23 | 23 | def parse_cmd_line_arguments():
|
24 | 24 | parser = argparse.ArgumentParser(
|
25 |
| - prog="RP Tree", |
26 |
| - description="Directory Tree Generator", |
27 |
| - epilog="Thanks for Using RP Tree!", |
| 25 | + prog="tree", |
| 26 | + description="RP Tree, a directory tree generator", |
| 27 | + epilog="Thanks for using RP Tree!", |
28 | 28 | )
|
29 |
| - parser.version = f"{parser.prog} {__version__}" |
| 29 | + parser.version = f"RP Tree v{__version__}" |
| 30 | + parser.add_argument("-v", "--version", action="version") |
30 | 31 | parser.add_argument(
|
31 | 32 | "root_dir",
|
32 | 33 | metavar="ROOT_DIR",
|
33 | 34 | nargs="?",
|
34 | 35 | default=".",
|
35 |
| - type=str, |
36 |
| - help="Generate a Full and Recursive Directory Tree", |
| 36 | + help="Generate a full directory tree starting at ROOT_DIR", |
37 | 37 | )
|
38 | 38 | parser.add_argument(
|
39 | 39 | "-d",
|
40 | 40 | "--dir-only",
|
41 | 41 | action="store_true",
|
42 |
| - help="Generate a Directory-Only Tree", |
| 42 | + help="Generate a directory-only tree", |
43 | 43 | )
|
44 | 44 | parser.add_argument(
|
45 | 45 | "-o",
|
46 | 46 | "--output-file",
|
47 | 47 | metavar="OUTPUT_FILE",
|
48 | 48 | nargs="?",
|
49 | 49 | default=sys.stdout,
|
50 |
| - type=str, |
51 |
| - help="Generate a Full Directory Tree and Save it to a File", |
| 50 | + help="Generate a full directory tree and save it to a file", |
52 | 51 | )
|
53 |
| - parser.add_argument("-v", "--version", action="version") |
54 | 52 | return parser.parse_args()
|
0 commit comments