def dispatch_command(function, *args, **kwargs): """ A wrapper for :func:`dispatch` that creates a one-command parser. Uses :attr:`PARSER_FORMATTER`. This:: dispatch_command(foo) ...is a shortcut for:: parser = ArgumentParser() set_default_command(parser, foo) dispatch(parser) This function can be also used as a decorator. """ parser = argparse.ArgumentParser(formatter_class=PARSER_FORMATTER) set_default_command(parser, function) dispatch(parser, *args, **kwargs)
def set_default_command(self, *args, **kwargs): "Wrapper for :func:`set_default_command`." return set_default_command(self, *args, **kwargs)
@argh.arg('--host', default='jira.findmeals.ru') @argh.arg('--port', default=443) @argh.arg('--user') @argh.arg('--password') @argh.arg('commit_msg_file') def main(args): connobj = JiraConnection(args.host, args.port, args.user, args.password) connobj.login() with open(args.commit_msg_file, 'r+') as f: text = ''.join(f.readlines()).strip() text = re.sub('^#.*\n', '', text, flags=re.M) # strip comments f.seek(0) f.truncate() regexp = re.compile(r'\s*refs #newissue\s+(?P<project>\w+)(?P<parent>-\d+)?\s*') matchobj = regexp.search(text) if matchobj: text = create_issue(connobj, matchobj, text) else: text = re.sub(r'refs #(\w+-\d+)', lambda x: replace_func(connobj, text, x), text) f.write(text+'\n') if __name__ == '__main__': parser = argh.ArghParser() set_default_command(parser, main) parser.dispatch()
def set_default_command(self, *args, **kwargs): "Wrapper for :func:`~argh.assembling.set_default_command`." return set_default_command(self, *args, **kwargs)