8000 Multiple refactors on main() and parse_cmd_line_arguments(). · realpython/rptree@6772f93 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6772f93

Browse files
committed
Multiple refactors on main() and parse_cmd_line_arguments().
On main(): - Remove blank likes - Update the order of the arguments to DirectoryTree constructor On parse_cmd_line_arguments(): - Remove unneeded upper case letter from strings - Move the version attribute up - Remove the unneeded type argument because str is the default type for command-line arguments
1 parent a5d424d commit 6772f93

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

rptree/cli.py

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""This module provides RP Tree cli."""
1+
"""This module provides the RP Tree CLI."""
22

33
import argparse
44
import pathlib
@@ -11,44 +11,42 @@
1111
def main():
1212
args = parse_cmd_line_arguments()
1313
root_dir = pathlib.Path(args.root_dir)
14-
1514
if not root_dir.is_dir():
1615
print("The specified root directory doesn't exist")
1716
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+
)
2020
tree.generate()
2121

2222

2323
def parse_cmd_line_arguments():
2424
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!",
2828
)
29-
parser.version = f"{parser.prog} {__version__}"
29+
parser.version = f"RP Tree v{__version__}"
30+
parser.add_argument("-v", "--version", action="version")
3031
parser.add_argument(
3132
"root_dir",
3233
metavar="ROOT_DIR",
3334
nargs="?",
3435
default=".",
35-
type=str,
36-
help="Generate a Full and Recursive Directory Tree",
36+
help="Generate a full directory tree starting at ROOT_DIR",
3737
)
3838
parser.add_argument(
3939
"-d",
4040
"--dir-only",
4141
action="store_true",
42-
help="Generate a Directory-Only Tree",
42+
help="Generate a directory-only tree",
4343
)
4444
parser.add_argument(
4545
"-o",
4646
"--output-file",
4747
metavar="OUTPUT_FILE",
4848
nargs="?",
4949
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",
5251
)
53-
parser.add_argument("-v", "--version", action="version")
5452
return parser.parse_args()

0 commit comments

Comments
 (0)
0