Skip to content
This repository was archived by the owner on Mar 7, 2021. It is now read-only.

Commit 350a04f

Browse files
add basic command line UI with optparse
1 parent 8d20819 commit 350a04f

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

bin/pyflakes

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#!/usr/bin/python
22

3-
from pyflakes.scripts.pyflakes import main
3+
from pyflakes.scripts.pyflakes_cmd import main
44
main()

pyflakes/scripts/pyflakes.py renamed to pyflakes/scripts/pyflakes_cmd.py

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66
import sys
77
import os
88
import _ast
9+
import textwrap
10+
from optparse import OptionParser
911

10-
checker = __import__('pyflakes.checker').checker
12+
from pyflakes import checker, __version__
1113

1214
def check(codeString, filename):
1315
"""
@@ -73,8 +75,26 @@ def checkPath(filename):
7375

7476

7577
def main():
78+
usage=textwrap.dedent("""\
79+
pyflakes [PATH [PATH]]
80+
81+
Checks Python source files for error in each PATH.
82+
(PATH can be a Python file or a directory)
83+
If no paths are specified, checks source provided on stdin.\
84+
""")
85+
parser = OptionParser(usage=usage)
86+
parser.add_option('-v', '--verbose', action='store_true',
87+
dest='verbose', default=False,
88+
help='increase output verbosity (not yet implemented)')
89+
parser.add_option('-V','--version', action='store_true',
90+
dest='version',
91+
help='show version information and exit')
92+
(options, args) = parser.parse_args()
93+
94+
if options.version:
95+
sys.exit('pyflakes %s' % __version__)
96+
7697
warnings = 0
77-
args = sys.argv[1:]
7898
if args:
7999
for arg in args:
80100
if os.path.isdir(arg):
@@ -88,3 +108,6 @@ def main():
88108
warnings += check(sys.stdin.read(), '<stdin>')
89109

90110
raise SystemExit(warnings > 0)
111+
112+
if __name__ == '__main__':
113+
main()

0 commit comments

Comments
 (0)