From: W. Trevor King Date: Wed, 12 Mar 2014 16:58:44 +0000 (-0700) Subject: irkerd: Fix -i / --immediate handling, and add a message argument X-Git-Tag: 2.7~4 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=35e07773867f52c3221cea89fa5ac11f042dae97;p=irker.git irkerd: Fix -i / --immediate handling, and add a message argument This fixes some problems with -i/--immediate parsing in ccd311c5 (irkerd: Transition from getopt to argparse, 2014-03-06). > + parser.add_argument( > + '-i', '--immediate', action='store_const', const=True, > + help='disconnect after sending each message') This does not match the old syntax where -i took two arguments (an IRC URL and a message). > - if immediate: > + if args.immediate: > irker.irc.add_event_handler("quit", lambda _c, _e: sys.exit(0)) > irker.handle('{"to":"%s","privmsg":"%s"}' % (immediate, arguments[0]), quit_after=True) > irker.irc.spin() immediate should be args.immediate, and arguments[0] needs to be added as a new (optional) positional argument. This patch fixes both issues. --- diff --git a/irkerd b/irkerd index 1e2d0af..ea9aa06 100755 --- a/irkerd +++ b/irkerd @@ -953,11 +953,16 @@ if __name__ == '__main__': '-p', '--password', metavar='PASSWORD', help='NickServ password') parser.add_argument( - '-i', '--immediate', action='store_const', const=True, - help='disconnect after sending each message') + '-i', '--immediate', metavar='IRC-URL', + help=( + 'send a single message to IRC-URL and exit. The message is the ' + 'first positional argument.')) parser.add_argument( '-V', '--version', action='version', version='%(prog)s {0}'.format(version)) + parser.add_argument( + 'message', metavar='MESSAGE', nargs='?', + help='message for --immediate mode') args = parser.parse_args() handler = logging.StreamHandler() @@ -975,10 +980,21 @@ if __name__ == '__main__': ) LOG.info("irkerd version %s" % version) if args.immediate: + if not args.message: + LOG.error( + '--immediate set (%r), but message argument not given' % ( + args.immediate)) + raise SystemExit(1) irker.irc.add_event_handler("quit", lambda _c, _e: sys.exit(0)) - irker.handle('{"to":"%s","privmsg":"%s"}' % (args.immediate, arguments[0]), quit_after=True) + irker.handle('{"to":"%s","privmsg":"%s"}' % ( + args.immediate, args.message), quit_after=True) irker.irc.spin() else: + if args.message: + LOG.error( + 'message argument given (%r), but --immediate not set' % ( + args.message)) + raise SystemExit(1) irker.thread_launch() try: tcpserver = socketserver.TCPServer((HOST, PORT), IrkerTCPHandler)