Skip to content

Commit 1f3682d

Browse files
committed
[__main__] add external diff color support and argument validations
1 parent fa2f5b9 commit 1f3682d

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

lib/fdiff/__main__.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,13 +114,23 @@ def run(argv):
114114
exclude_list = get_tables_argument_list(args.exclude)
115115

116116
# flip logic of the command line flag for multi process
117-
# optimizations for use as a u_diff function argument
117+
# optimization use
118118
use_mp = not args.nomp
119119

120120
if args.external:
121121
# ------------------------------
122122
# External executable tool diff
123123
# ------------------------------
124+
# head and tail are not supported when external diff tool is called
125+
if args.head or args.tail:
126+
sys.stderr.write(f"[ERROR] The head and tail options are not supported with external diff executable calls.{os.linesep}")
127+
sys.exit(1)
128+
129+
# lines of context filter is not supported when external diff tool is called
130+
if args.lines != 3:
131+
sys.stderr.write(f"[ERROR] The lines option is not supported with external diff executable calls.{os.linesep}")
132+
sys.exit(1)
133+
124134
try:
125135
diff = external_diff(
126136
args.external,
@@ -133,8 +143,11 @@ def run(argv):
133143

134144
# write stdout from external tool
135145
for line, exit_code in diff:
136-
# if exit_code is None:
137-
sys.stdout.write(line)
146+
# format with color if color flag is entered on command line
147+
if args.color:
148+
sys.stdout.write(color_unified_diff_line(line))
149+
else:
150+
sys.stdout.write(line)
138151
if exit_code is not None:
139152
sys.exit(exit_code)
140153
except Exception as e:

0 commit comments

Comments
 (0)