Skip to content

Commit 1a1b1bb

Browse files
committed
Split argument processing into two steps
1 parent 79e1a7c commit 1a1b1bb

File tree

1 file changed

+20
-13
lines changed

1 file changed

+20
-13
lines changed

lib/fdiff/__main__.py

+20-13
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ def run(argv):
3535
description="An OpenType table diff tool for fonts."
3636
)
3737
parser.add_argument("--version", action="version", version=f"fdiff v{__version__}")
38-
parser.add_argument("--git", type=str, nargs=7, help="Act as a diff driver for git (takes 7 parameters)")
3938
parser.add_argument(
4039
"-c",
4140
"--color",
@@ -65,15 +64,23 @@ def run(argv):
6564
"--nomp", action="store_true", help="Do not use multi process optimizations"
6665
)
6766
parser.add_argument("--external", type=str, help="Run external diff tool command")
67+
68+
parser.add_argument("--git", type=str, nargs=7, help="Act as a diff driver for git (takes 7 parameters)")
6869
# parser.add_argument("PREFILE", help="Font file path/URL 1")
6970
# parser.add_argument("POSTFILE", help="Font file path/URL 2")
7071

71-
args = parser.parse_args(argv)
72+
args, positionals = parser.parse_known_args(argv)
7273

74+
inputs = argparse.Namespace()
7375
if args.git:
74-
print(args.git)
75-
args.PREFILE = args.git[1]
76-
args.POSTFILE = args.git[4]
76+
inputs.PREFILE = args.git[1]
77+
inputs.POSTFILE = args.git[4]
78+
else:
79+
inputparser = argparse.ArgumentParser()
80+
inputparser.add_argument("PREFILE", help="Font file path/URL 1")
81+
inputparser.add_argument("POSTFILE", help="Font file path/URL 2")
82+
inputparser.parse_args(positionals, namespace=inputs)
83+
7784

7885
# /////////////////////////////////////////////////////////
7986
#
@@ -85,14 +92,14 @@ def run(argv):
8592
# File path argument validations
8693
# -------------------------------
8794

88-
if not args.PREFILE.startswith("http") and not file_exists(args.PREFILE):
95+
if not inputs.PREFILE.startswith("http") and not file_exists(inputs.PREFILE):
8996
sys.stderr.write(
90-
f"[*] ERROR: The file path '{args.PREFILE}' can not be found.{os.linesep}"
97+
f"[*] ERROR: The file path '{inputs.PREFILE}' can not be found.{os.linesep}"
9198
)
9299
sys.exit(1)
93-
if not args.POSTFILE.startswith("http") and not file_exists(args.POSTFILE):
100+
if not inputs.POSTFILE.startswith("http") and not file_exists(inputs.POSTFILE):
94101
sys.stderr.write(
95-
f"[*] ERROR: The file path '{args.POSTFILE}' can not be found.{os.linesep}"
102+
f"[*] ERROR: The file path '{inputs.POSTFILE}' can not be found.{os.linesep}"
96103
)
97104
sys.exit(1)
98105

@@ -134,8 +141,8 @@ def run(argv):
134141
try:
135142
diff = external_diff(
136143
args.external,
137-
args.PREFILE,
138-
args.POSTFILE,
144+
inputs.PREFILE,
145+
inputs.POSTFILE,
139146
include_tables=include_list,
140147
exclude_tables=exclude_list,
141148
use_multiprocess=use_mp,
@@ -160,8 +167,8 @@ def run(argv):
160167
# perform the unified diff analysis
161168
try:
162169
diff = u_diff(
163-
args.PREFILE,
164-
args.POSTFILE,
170+
inputs.PREFILE,
171+
inputs.POSTFILE,
165172
context_lines=args.lines,
166173
include_tables=include_list,
167174
exclude_tables=exclude_list,

0 commit comments

Comments
 (0)