summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlasdair Colley <alnessy@hotmail.com>2014-07-17 17:28:04 +0200
committerAlasdair Colley <alnessy@hotmail.com>2014-07-17 17:28:04 +0200
commitc4acf3fba0c35e236bf4b248d0810ab364f34a14 (patch)
tree412b19b93dcad901a149096e148b8969a6de5503
parent10a3d0e498b9305809c6efdefc25da994f458666 (diff)
supports stdin
-rwxr-xr-xsaucypy9
1 files 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 <term> | !source --add <key> <value>" )
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()
+