diff --git a/zulip/zulip/api_examples.py b/zulip/zulip/api_examples.py index 67a9da1..b755c29 100644 --- a/zulip/zulip/api_examples.py +++ b/zulip/zulip/api_examples.py @@ -2,14 +2,26 @@ import os import zulip +import argparse + def main(): + usage = """zulip-api-examples [script_name] + +Prints the path to the Zulip API example scripts.""" + parser = argparse.ArgumentParser(usage=usage) + parser.add_argument('script_name', + nargs='?', + default='', + help='print path to the script ') + args = parser.parse_args() zulip_path = os.path.abspath(os.path.dirname(zulip.__file__)) - examples_path = os.path.abspath(os.path.join(zulip_path, 'examples')) - if os.path.isdir(examples_path): + examples_path = os.path.abspath(os.path.join(zulip_path, 'examples', args.script_name)) + if os.path.isdir(examples_path) or (args.script_name and os.path.isfile(examples_path)): print(examples_path) else: - raise OSError("Examples cannot be accessed at {}: Directory does not exist!" - .format(examples_path)) + raise OSError("Examples cannot be accessed at {}: {} does not exist!" + .format(examples_path, + "File" if args.script_name else "Directory")) if __name__ == '__main__': main()