diff options
author | Alasdair <alnessy@hotmail.com> | 2013-08-23 19:27:38 +0200 |
---|---|---|
committer | Alasdair <alnessy@hotmail.com> | 2013-08-23 19:27:38 +0200 |
commit | db76e721914a0128e4f4afb3fabdb8d7ffaec78a (patch) | |
tree | a1837a8f4a98f6c6a0e676ec02d2cfabcf536654 | |
parent | d2b13b1823fd94ff6a41fdefa11f4a6403dea779 (diff) |
adding --version option
-rwxr-xr-x | wikiquery | 12 |
1 files changed, 10 insertions, 2 deletions
@@ -1,26 +1,34 @@ #! /usr/bin/env python import argparse +import sys import wikipedia +version = "0.0.1" + def parse_args(): parser = argparse.ArgumentParser() - parser.add_argument("topic", nargs=1) + parser.add_argument("topic", nargs="*") parser.add_argument("--search", action="store_true") parser.add_argument("--url", action="store_true") + parser.add_argument("-v", "--version", action="store_true") return parser.parse_args() def main(): args = parse_args() + + if args.version: + print version + sys.exit(0) if args.search: print wikipedia.search(args.topic) elif args.url: page = wikipedia.page(args.topic) print page.url - else: + elif args.topic: print wikipedia.summary(args.topic) if __name__ == "__main__": |