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