Mercurial > hg > GlobalNeighbors
view globalneighbors/cli.py @ 4:8e130b7bfed9
remove unintended boilerplate
author | Jeff Hammel <k0scist@gmail.com> |
---|---|
date | Sat, 24 Jun 2017 14:48:55 -0700 |
parents | 5dba84370182 |
children |
line wrap: on
line source
""" command line interfaces """ import argparse from .read import read_cities from .schema import fields class ValidationParser(argparse.ArgumentParser): """CLI option parser""" def __init__(self, **kwargs): kwargs.setdefault('formatter_class', argparse.RawTextHelpFormatter) argparse.ArgumentParser.__init__(self, **kwargs) self.add_arguments() self.options = None def add_arguments(self): """Abstract Base Class: add your arguments here""" def parse_args(self, *args, **kw): options = argparse.ArgumentParser.parse_args(self, *args, **kw) self.validate(options) self.options = options return options def validate(self, options): """validate options""" class CitiesParser(ValidationParser): def add_arguments(self): self.add_argument('cities', type=argparse.FileType('r'), help="path to TSV cities file, as documented in http://download.geonames.org/export/dump/") def read_cities(self): assert self.options return read_cities(self.options.cities, fields=fields)