html-grep: Replace optparse with argparse.

Tweated by tabbott to still have a useful description.
This commit is contained in:
rht
2017-09-30 08:42:22 +02:00
committed by Tim Abbott
parent 3ac8ab8be3
commit f6e6e8ba44

View File

@@ -1,6 +1,6 @@
#!/usr/bin/env python3
from lib.html_grep import grep
import optparse
import argparse
import sys
from six.moves import filter
@@ -45,30 +45,31 @@ USAGE = '''
the extension .html or .handlebars., and then it does
the grep against all those files.
TODO: allow specific files to be searched.
'''
TODO: allow specific files to be searched.'''
def check_our_files():
# type: () -> None
parser = optparse.OptionParser(usage=USAGE)
parser.add_option('--modified', '-m',
action='store_true', default=False,
help='Only check modified files')
parser.add_option('--no-filter', '-a',
dest='show_all',
action='store_true', default=False,
help='Show all HTML files (no filtering)')
(options, args) = parser.parse_args()
parser = argparse.ArgumentParser(description=USAGE,
formatter_class=argparse.RawTextHelpFormatter)
parser.add_argument('--modified', '-m',
action='store_true', default=False,
help='Only check modified files')
parser.add_argument('--no-filter', '-a',
dest='show_all',
action='store_true', default=False,
help='Show all HTML files (no filtering)')
parser.add_argument("keyword", nargs="*", help='keyword to be searched')
options = parser.parse_args()
if options.show_all:
keywords = [] # type: List[str]
else:
if not args:
if not options.keyword:
print('No keywords specified...try --help or --no-filter')
sys.exit(1)
else:
keywords = args
keywords = options.keyword
files = lister.list_files(
modified_only=options.modified,