88
99"""
1010
11- import sys , os , time , difflib , optparse
11+ import sys , os , time , difflib , argparse
1212from datetime import datetime , timezone
1313
1414def file_mtime (path ):
@@ -18,23 +18,25 @@ def file_mtime(path):
1818
1919def main ():
2020
21- usage = "usage: %prog [options] fromfile tofile"
22- parser = optparse .OptionParser (usage )
23- parser .add_option ("-c" , action = "store_true" , default = False , help = 'Produce a context format diff (default)' )
24- parser .add_option ("-u" , action = "store_true" , default = False , help = 'Produce a unified format diff' )
25- parser .add_option ("-m" , action = "store_true" , default = False , help = 'Produce HTML side by side diff (can use -c and -l in conjunction)' )
26- parser .add_option ("-n" , action = "store_true" , default = False , help = 'Produce a ndiff format diff' )
27- parser .add_option ("-l" , "--lines" , type = "int" , default = 3 , help = 'Set number of context lines (default 3)' )
28- (options , args ) = parser .parse_args ()
29-
30- if len (args ) == 0 :
31- parser .print_help ()
32- sys .exit (1 )
33- if len (args ) != 2 :
34- parser .error ("need to specify both a fromfile and tofile" )
21+ parser = argparse .ArgumentParser ()
22+ parser .add_argument ('-c' , action = 'store_true' , default = False ,
23+ help = 'Produce a context format diff (default)' )
24+ parser .add_argument ('-u' , action = 'store_true' , default = False ,
25+ help = 'Produce a unified format diff' )
26+ parser .add_argument ('-m' , action = 'store_true' , default = False ,
27+ help = 'Produce HTML side by side diff '
28+ '(can use -c and -l in conjunction)' )
29+ parser .add_argument ('-n' , action = 'store_true' , default = False ,
30+ help = 'Produce a ndiff format diff' )
31+ parser .add_argument ('-l' , '--lines' , type = int , default = 3 ,
32+ help = 'Set number of context lines (default 3)' )
33+ parser .add_argument ('fromfile' )
34+ parser .add_argument ('tofile' )
35+ options = parser .parse_args ()
3536
3637 n = options .lines
37- fromfile , tofile = args
38+ fromfile = options .fromfile
39+ tofile = options .tofile
3840
3941 fromdate = file_mtime (fromfile )
4042 todate = file_mtime (tofile )
0 commit comments