Commit ba7ee08b authored by Tails developers's avatar Tails developers
Browse files

Do proper option parsing.

parent 2f7a268b
...@@ -3,6 +3,7 @@ import sys ...@@ -3,6 +3,7 @@ import sys
import jabberbot import jabberbot
import xmpp import xmpp
import otr import otr
from argparse import ArgumentParser
# Minimal implementation of the OTR callback store that only does what # Minimal implementation of the OTR callback store that only does what
# we absolutely need. # we absolutely need.
...@@ -147,14 +148,18 @@ class OtrBot(jabberbot.JabberBot): ...@@ -147,14 +148,18 @@ class OtrBot(jabberbot.JabberBot):
return "" return ""
if __name__ == '__main__': if __name__ == '__main__':
if len(sys.argv) < 4: parser = ArgumentParser()
print >> sys.stderr, \ parser.add_argument("account",
"Usage: %s <user@domain> <password> <otr_key_file> [rooms...]" \ help = "the user account, given as user@domain")
% sys.argv[0] parser.add_argument("password",
sys.exit(1) help = "the user account's password")
username, password, otr_key_path = sys.argv[1:4] parser.add_argument("otr_key_path",
rooms = sys.argv[4:] help = "the path to the account's OTR key file")
otr_bot = OtrBot(username, password, otr_key_path) parser.add_argument("-j", "--auto-join", nargs = '+', metavar = 'ROOMS',
for room in rooms: help = "auto-join multi-user chatrooms on start")
otr_bot.join_room(room) args = parser.parse_args()
otr_bot = OtrBot(args.account, args.password, args.otr_key_path)
if args.auto_join:
for room in args.auto_join:
otr_bot.join_room(room)
otr_bot.serve_forever() otr_bot.serve_forever()
...@@ -22,7 +22,7 @@ class ChatBot ...@@ -22,7 +22,7 @@ class ChatBot
@password, @password,
@otr_key_file.path @otr_key_file.path
] ]
cmd += @rooms if @rooms cmd += ["--auto-join"] + @rooms if @rooms
job = IO.popen(cmd) job = IO.popen(cmd)
@pid = job.pid @pid = job.pid
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment