1
1
#!/usr/bin/env python3
2
2
# -*- coding: utf-8 -*-
3
3
4
+ import os
4
5
import sys
5
6
import argparse
6
7
7
8
from fdiff import __version__
9
+ from fdiff .color import color_unified_diff_line
10
+ from fdiff .diff import u_diff
11
+ from fdiff .utils import file_exists
8
12
9
13
10
14
def main (): # pragma: no cover
@@ -15,19 +19,40 @@ def run(argv):
15
19
# ===========================================================
16
20
# argparse command line argument definitions
17
21
# ===========================================================
18
- parser = argparse .ArgumentParser (
19
- description = "A font OpenType table diff tool"
20
- )
22
+ parser = argparse .ArgumentParser (description = "A font OpenType table diff tool" )
21
23
parser .add_argument (
22
24
"--version" , action = "version" , version = "fdiff v{}" .format (__version__ )
23
25
)
24
- parser .add_argument ('-c' , action = 'store_true' , default = False ,
25
- help = 'ANSI escape code colored diff' )
26
- parser .add_argument ('-l' , '--lines' , type = int , default = 3 ,
27
- help = 'Number of context lines (default 3)' )
28
- parser .add_argument ('PREFILE' ,
29
- help = 'Font file path 1' )
30
- parser .add_argument ('POSTFILE' ,
31
- help = 'Font file path 2' )
26
+ parser .add_argument (
27
+ "-c" ,
28
+ "--color" ,
29
+ action = "store_true" ,
30
+ default = False ,
31
+ help = "ANSI escape code colored diff" ,
32
+ )
33
+ parser .add_argument (
34
+ "-l" , "--lines" , type = int , default = 3 , help = "Number of context lines (default 3)"
35
+ )
36
+ parser .add_argument ("PREFILE" , help = "Font file path 1" )
37
+ parser .add_argument ("POSTFILE" , help = "Font file path 2" )
32
38
33
39
args = parser .parse_args (argv )
40
+
41
+ if not file_exists (args .PREFILE ):
42
+ sys .stderr .write (
43
+ f"[*] ERROR: The file path '{ args .PREFILE } ' can not be found.{ os .linesep } "
44
+ )
45
+ sys .exit (1 )
46
+ if not file_exists (args .POSTFILE ):
47
+ sys .stderr .write (
48
+ f"[*] ERROR: The file path '{ args .POSTFILE } ' can not be found.{ os .linesep } "
49
+ )
50
+ sys .exit (1 )
51
+
52
+ diff = u_diff (args .PREFILE , args .POSTFILE , context_lines = args .lines )
53
+
54
+ if args .color :
55
+ for line in diff :
56
+ sys .stdout .write (color_unified_diff_line (line ))
57
+ else :
58
+ sys .stdout .writelines (diff )
0 commit comments