def docopt(usage, **keywords): new_usage = usage if "program" in keywords: program = keywords.pop("program") new_usage = usage.replace(program, program.replace(" ", "-")) try: stdout = sys.stdout with open(os.devnull, 'w') as f: sys.stdout = f arguments = real_docopt(new_usage, **keywords) sys.stdout = stdout return arguments except DocoptExit: sys.stdout = stdout print >> sys.stderr, usage.strip() sys.exit(1) except SystemExit: sys.stdout = stdout if "argv" in keywords and any(h in ("-h", "--help") for h in keywords["argv"]): print usage.strip() elif "version" in keywords and any(v in ("--version") for v in keywords["argv"]): print keywords["version"].strip() sys.exit()
def docopt(usage, **keywords): """ A wrapper around the real docopt parser. """ new_usage = usage if "program" in keywords: program = keywords.pop("program") new_usage = usage.replace(program, program.replace(" ", "-")) try: stdout = sys.stdout with open(os.devnull, 'w') as nullfile: sys.stdout = nullfile arguments = real_docopt(new_usage, **keywords) sys.stdout = stdout return arguments except DocoptExit: sys.stdout = stdout print(usage.strip(), file=sys.stderr) sys.exit(1) except SystemExit: sys.stdout = stdout if "argv" in keywords and any(h in ("-h", "--help") for h in keywords["argv"]): print(usage.strip()) elif "version" in keywords and any(v in ("--version") for v in keywords["argv"]): print(keywords["version"].strip()) sys.exit()
def docopt(usage, **keywords): """ A wrapper around the real docopt parser. """ new_usage = usage if "program" in keywords: program = keywords.pop("program") new_usage = usage.replace(program, program.replace(" ", "-")) try: stdout = sys.stdout with open(os.devnull, "w") as nullfile: sys.stdout = nullfile arguments = real_docopt(new_usage, **keywords) sys.stdout = stdout return arguments except DocoptExit: sys.stdout = stdout print >> sys.stderr, usage.strip() sys.exit(1) except SystemExit: sys.stdout = stdout if "argv" in keywords and any(h in ("-h", "--help") for h in keywords["argv"]): print usage.strip() elif "version" in keywords and any(v in ("--version") for v in keywords["argv"]): print keywords["version"].strip() sys.exit()
def docopt(usage, **keywords): """ A wrapper around the real docopt parser. """ new_usage = usage if "programs" in keywords: programs = keywords.pop("programs") for program in programs: new_usage = new_usage.replace(program, "__placeholder__") try: stdout = sys.stdout with open(os.devnull, 'w') as nullfile: sys.stdout = nullfile arguments = real_docopt(new_usage, **keywords) sys.stdout = stdout return arguments except DocoptExit: sys.stdout = stdout print >> sys.stderr, usage.strip() sys.exit(1) except SystemExit: sys.stdout = stdout if "argv" in keywords and any(h in ("-h", "--help") for h in keywords["argv"]): print usage.strip() elif "version" in keywords and any(v in ("--version") for v in keywords["argv"]): print keywords["version"].strip() sys.exit()