From c4acf3fba0c35e236bf4b248d0810ab364f34a14 Mon Sep 17 00:00:00 2001 From: Alasdair Colley Date: Thu, 17 Jul 2014 17:28:04 +0200 Subject: supports stdin --- saucypy | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/saucypy b/saucypy index 745e93d..f24fcab 100755 --- a/saucypy +++ b/saucypy @@ -3,6 +3,7 @@ import difflib import json import optparse +import shlex import sys VERSION = "1.0.0" @@ -13,11 +14,14 @@ def find( key, entries ): return difflib.get_close_matches( key, entries.keys() ) def parse_args(): - parser = optparse.OptionParser() + args = sys.argv[1:] + if not args: + args = shlex.split( sys.stdin.read() ) + parser = optparse.OptionParser( usage = "!source | !source --add " ) parser.add_option( "-a", "--add", action = "store", nargs = 2 ) parser.add_option( "-i", "--index", action = "store", type = int ) parser.add_option( "-v", "--version", action = "store_true" ) - return parser.parse_args() + return parser.parse_args( args ) def main(): options, args = parse_args() @@ -58,3 +62,4 @@ def main(): if __name__ == "__main__": main() + -- cgit v1.2.3