@@ -16,13 +16,15 @@ def get_arguments():
16
16
stripped. The reason why we print out the line with whitespace stripped is
17
17
that in the case where there is a lot of redundant whitespace, the output
18
18
becomes hard to read and no value is provided in terms of finding the line
19
- in question.""" ))
19
+ in question.
20
+
21
+ Exits with 1 if it finds any violating lines, 0 otherwise.""" ))
20
22
21
23
parser .add_argument ('infile' , nargs = '?' , type = argparse .FileType ('r' ),
22
24
default = sys .stdin ,
23
25
help = textwrap .dedent ("""The file to read input from. If
24
26
no file is provided, stdin is used.""" ))
25
- parser .add_argument ('-o' , type = argparse .FileType ('w' ),
27
+ parser .add_argument ('-o' , '--output' , type = argparse .FileType ('w' ),
26
28
default = sys .stdout ,
27
29
help = textwrap .dedent ("""The file to print to. If no
28
30
file is provided, stdout is used""" ),
@@ -37,17 +39,15 @@ def get_arguments():
37
39
38
40
args = get_arguments ()
39
41
40
- count = 0
41
42
found_violation = False
42
43
43
- for l in args .infile :
44
+ for lineno , line in enumerate ( args .infile , start = 1 ) :
44
45
# sys.stdin.readlines() includes a newline. So we subtract 1 from our
45
46
# length to get the "true" line length.
46
- length = len (l ) - int (args .count_newline )
47
+ length = len (line ) - int (args .count_newline )
47
48
if length > args .max_length :
48
49
found_violation = True
49
- print ("line: {}. length: {}: {}" .format (count , length , l .strip ()),
50
+ print ("line: {}. length: {}: {}" .format (lineno , length , line .strip ()),
50
51
file = args .outfile )
51
- count += 1
52
52
53
53
sys .exit (found_violation )
0 commit comments