add usage() function, -h(elp) flag and long versions of short flags
This commit is contained in:
parent
dbb407808a
commit
165163f245
|
@ -4,9 +4,10 @@
|
||||||
|
|
||||||
"""reindent [-d][-r][-v] [ path ... ]
|
"""reindent [-d][-r][-v] [ path ... ]
|
||||||
|
|
||||||
-d Dry run. Analyze, but don't make any changes to, files.
|
-d (--dryrun) Dry run. Analyze, but don't make any changes to, files.
|
||||||
-r Recurse. Search for all .py files in subdirectories too.
|
-r (--recurse) Recurse. Search for all .py files in subdirectories too.
|
||||||
-v Verbose. Print informative msgs; else no output.
|
-v (--verbose) Verbose. Print informative msgs; else no output.
|
||||||
|
-h (--help) Help. Print this usage information and exit.
|
||||||
|
|
||||||
Change Python (.py) files to use 4-space indents and no hard tab characters.
|
Change Python (.py) files to use 4-space indents and no hard tab characters.
|
||||||
Also trim excess spaces and tabs from ends of lines, and remove empty lines
|
Also trim excess spaces and tabs from ends of lines, and remove empty lines
|
||||||
|
@ -42,6 +43,11 @@ verbose = 0
|
||||||
recurse = 0
|
recurse = 0
|
||||||
dryrun = 0
|
dryrun = 0
|
||||||
|
|
||||||
|
def usage(msg=None):
|
||||||
|
if msg is not None:
|
||||||
|
print >> sys.stderr, msg
|
||||||
|
print >> sys.stderr, __doc__
|
||||||
|
|
||||||
def errprint(*args):
|
def errprint(*args):
|
||||||
sep = ""
|
sep = ""
|
||||||
for arg in args:
|
for arg in args:
|
||||||
|
@ -53,17 +59,21 @@ def main():
|
||||||
import getopt
|
import getopt
|
||||||
global verbose, recurse, dryrun
|
global verbose, recurse, dryrun
|
||||||
try:
|
try:
|
||||||
opts, args = getopt.getopt(sys.argv[1:], "drv")
|
opts, args = getopt.getopt(sys.argv[1:], "drvh",
|
||||||
|
["dryrun", "recurse", "verbose", "help"])
|
||||||
except getopt.error, msg:
|
except getopt.error, msg:
|
||||||
errprint(msg)
|
usage(msg)
|
||||||
return
|
return
|
||||||
for o, a in opts:
|
for o, a in opts:
|
||||||
if o == '-d':
|
if o in ('-d', '--dryrun'):
|
||||||
dryrun += 1
|
dryrun += 1
|
||||||
elif o == '-r':
|
elif o in ('-r', '--recurse'):
|
||||||
recurse += 1
|
recurse += 1
|
||||||
elif o == '-v':
|
elif o in ('-v', '--verbose'):
|
||||||
verbose += 1
|
verbose += 1
|
||||||
|
elif o in ('-h', '--help'):
|
||||||
|
usage()
|
||||||
|
return
|
||||||
if not args:
|
if not args:
|
||||||
r = Reindenter(sys.stdin)
|
r = Reindenter(sys.stdin)
|
||||||
r.run()
|
r.run()
|
||||||
|
|
Loading…
Reference in New Issue