FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Merge remote-tracking branch 'jdufresne/argparse' · feenes/unidecode@d31c815 · GitHub

Repository navigation

Commit d31c815

Browse files
committed
Merge remote-tracking branch 'jdufresne/argparse'
2 parents 6c96492 + 62a7e52 commit d31c815

1 file changed

Lines changed: 13 additions & 12 deletions

File tree

‎unidecode/util.py‎

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# vim:ts=4 sw=4 expandtab softtabstop=4
22
from __future__ import print_function
3-
import optparse
3+
import argparse
44
import locale
55
import os
66
import sys
@@ -16,29 +16,30 @@ def fatal(msg):
1616
def main():
1717
default_encoding = locale.getpreferredencoding()
1818

19-
parser = optparse.OptionParser('%prog [options] [FILE]',
19+
parser = argparse.ArgumentParser(
2020
description="Transliterate Unicode text into ASCII. FILE is path to file to transliterate. "
2121
"Standard input is used if FILE is omitted and -c is not specified.")
22-
parser.add_option('-e', '--encoding', metavar='ENCODING', default=default_encoding,
22+
parser.add_argument('-e', '--encoding', metavar='ENCODING', default=default_encoding,
2323
help='Specify an encoding (default is %s)' % (default_encoding,))
24-
parser.add_option('-c', metavar='TEXT', dest='text',
24+
parser.add_argument('-c', metavar='TEXT', dest='text',
2525
help='Transliterate TEXT instead of FILE')
26+
parser.add_argument('path', nargs='?', metavar='FILE')
2627

27-
options, args = parser.parse_args()
28+
args = parser.parse_args()
2829

29-
encoding = options.encoding
30+
encoding = args.encoding
3031

31-
if args:
32-
if options.text:
32+
if args.path:
33+
if args.text:
3334
fatal("Can't use both FILE and -c option")
3435
else:
35-
with open(args[0], 'rb') as f:
36+
with open(args.path, 'rb') as f:
3637
stream = f.read()
37-
elif options.text:
38+
elif args.text:
3839
if PY3:
39-
stream = os.fsencode(options.text)
40+
stream = os.fsencode(args.text)
4041
else:
41-
stream = options.text
42+
stream = args.text
4243
# add a newline to the string if it comes from the
4344
# command line so that the result is printed nicely
4445
# on the console.

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL