Commit 3e47689d authored by Christian Tacke's avatar Christian Tacke
Browse files

Refactor argument parser building

In order to allow easier testing of the argument parser,
refactor its setup into a function. Now we can
"from xmppnotify import build_argparser" and use it.
parent 7b7f460f
......@@ -97,13 +97,9 @@ Comment by {notificationauthorname}
return message
if __name__ == '__main__':
config = configparser.RawConfigParser()
config.read('/etc/xmppnotify.cfg')
jid = config.get('Account', 'jid')
password = config.get('Account', 'password')
def build_argparser():
parser = argparse.ArgumentParser(description='XMPP Notifications')
# required
parser.add_argument('-d', '--longdatetime')
parser.add_argument('-e', '--servicename') # service only
......@@ -122,6 +118,16 @@ if __name__ == '__main__':
parser.add_argument('-c', '--notificationcomment')
parser.add_argument('-i', '--icingaweb2url')
return parser
if __name__ == '__main__':
config = configparser.RawConfigParser()
config.read('/etc/xmppnotify.cfg')
jid = config.get('Account', 'jid')
password = config.get('Account', 'password')
parser = build_argparser()
args = parser.parse_args()
message = build_message(args)
......
Supports Markdown
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