diff options
| author | Devendra | 2014-04-25 19:42:21 +0530 |
|---|---|---|
| committer | Devendra | 2014-04-25 19:42:21 +0530 |
| commit | 44aee82f3eadea1241ac4350b4f9f34daf58eb87 (patch) | |
| tree | 1fb58322b718074b7b2e2e967ac52eaeafdd424a /python | |
| parent | 9e4032331721539d2b1e74b87b86ac5c66ccc4af (diff) | |
| download | pubnub-python-44aee82f3eadea1241ac4350b4f9f34daf58eb87.tar.bz2 | |
improvements to console
Diffstat (limited to 'python')
| -rw-r--r-- | python/examples/console.py | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/python/examples/console.py b/python/examples/console.py index 4dfd891..aa6fff3 100644 --- a/python/examples/console.py +++ b/python/examples/console.py @@ -12,7 +12,7 @@ from datetime import datetime from cmd2 import Cmd, make_option, options, Cmd2TestCase import optparse - +import json of=sys.stdout @@ -246,8 +246,7 @@ class DevConsole(Cmd): _history_command_handler(opts.channel, opts.count) - @options([make_option('-c', '--channel', action="store", help="Channel on which to publish"), - make_option('-m', '--message', action="store", help="Message to be published") + @options([make_option('-c', '--channel', action="store", help="Channel on which to publish") ]) def do_publish(self, command, opts): opts.channel = self.default_channel if opts.channel is None else opts.channel @@ -255,11 +254,16 @@ class DevConsole(Cmd): print_error("Missing channel") return - if opts.message is None: + if command is None: print_error("Missing message") return - _publish_command_handler(opts.channel,opts.message) + try: + message = json.loads(str(command)) + except ValueError as ve: + message = str(command) + + _publish_command_handler(opts.channel,message) @options([make_option('-c', '--channel', action="store", help="Channel on which to grant"), make_option('-a', '--auth-key', dest="auth_key", action="store", @@ -327,8 +331,6 @@ class DevConsole(Cmd): _subscribe_command_handler(opts.channel) - - def main(): app = DevConsole() app.cmdloop() |
