def main(): ap = argparse.ArgumentParser() ap.add_argument('--ignore-case', '-i', action='store_true', help='ignore case distinctions') ap.add_argument('--word-regexp', '-w', action='store_true', help='match only whole words') ap.add_argument('--fixed-string', '-F', action='store_true', help='interpret pattern as fixed string') ap.add_argument('--web-browser', '-W', action='store_true', help='spawn a web browser') ap.add_argument('--delay', default=200, type=int, help='minimum time between requests, in ms (default: 200)') ap.add_argument('query', metavar='QUERY') ap.add_argument('query_tail', nargs='*', help=argparse.SUPPRESS) options = ap.parse_args() options.delay /= 1000 query = [options.query] + options.query_tail [keywords, query] = lsplit(is_keyword, query) query = ' '.join(query) if options.fixed_string: query = re.escape(query) if options.word_regexp: if '|' in query: query = '(?:{query})'.format(query=query) query = r'\b{query}\b'.format(query=query) if options.ignore_case: query = '(?i)' + query options.query_regexp = query query = ' '.join([query] + keywords) options.query = query if options.web_browser: send_web_query(options) return with pager.autopager(): send_query(options)
def main(): ap = argparse.ArgumentParser() sp = ap.add_subparsers() sp.dest = 'cmd' # https://bugs.python.org/issue9253 sp.required = True for cmd in ['ls', 'show', 'new']: mod = importlib.import_module('lib.cmd.{cmd}'.format(cmd=cmd)) mod.add_argument_parser(sp) options = ap.parse_args() options.session = web.UserAgent() mod = importlib.import_module('lib.cmd.{cmd}'.format(cmd=options.cmd)) options.error = ap.error with pager.autopager(): mod.run(options)
def main(): ap = argparse.ArgumentParser() ap.add_argument('--force-cache', action='store_true', help=argparse.SUPPRESS) sp = ap.add_subparsers() sp.dest = 'cmd' # https://bugs.python.org/issue9253 sp.required = True for cmd in ['ls', 'show']: mod = importlib.import_module('lib.cmd.{cmd}'.format(cmd=cmd)) mod.add_argument_parser(sp) options = ap.parse_args() if options.force_cache: install_cache() session = requests.Session() session.verify = True session.trust_env = False session.headers['User-Agent'] = 'dbts (https://github.com/jwilk/dbts)' options.session = session mod = importlib.import_module('lib.cmd.{cmd}'.format(cmd=options.cmd)) options.error = ap.error with pager.autopager(): mod.run(options)