Use argparse for fusker.

This commit is contained in:
voussoir 2021-09-11 11:12:00 -07:00
parent 0416f0babf
commit df6a52452a
No known key found for this signature in database
GPG key ID: 5F7554F8C26DACCB

View file

@ -20,12 +20,14 @@ fusker.fusker('https://subdomain-{a|b|c}.website.com/image[01-99].jpg') ->
'https://subdomain-b.website.com/image02.jpg', 'https://subdomain-b.website.com/image02.jpg',
) )
''' '''
import argparse
import collections import collections
import itertools import itertools
import string import string
import sys import sys
from voussoirkit import basenumber from voussoirkit import basenumber
from voussoirkit import pipeable
class Landmark: class Landmark:
def __init__(self, opener, closer, parser): def __init__(self, opener, closer, parser):
@ -122,7 +124,6 @@ def parse_range(characters):
frange = fusk_range(lo, hi, padto=padto, base=base, lower=lower) frange = fusk_range(lo, hi, padto=padto, base=base, lower=lower)
return frange return frange
landmarks = { landmarks = {
'{': Landmark('{', '}', parse_spinner), '{': Landmark('{', '}', parse_spinner),
'[': Landmark('[', ']', parse_range), '[': Landmark('[', ']', parse_range),
@ -155,8 +156,19 @@ def fusker(fstring, landmark=None, depth=0):
return buff return buff
return result return result
def fusker_argparse(args):
for result in fusker(args.pattern):
pipeable.stdout(result)
return 0
def main(argv):
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('pattern')
parser.set_defaults(func=fusker_argparse)
args = parser.parse_args(argv)
return args.func(args)
if __name__ == '__main__': if __name__ == '__main__':
pattern = sys.argv[1] raise SystemExit(main(sys.argv[1:]))
fusk = fusker(pattern)
for result in fusk:
print(result)