#!/usr/bin/env python
# -*- coding: utf-8 -*-

# file: test_systemd_journal_argparse.py

# call with:
# --loglevel debug --verbose all --systemd-journal --syslog user --my_option barfoobar
# --loglevel debug --verbose all --systemd-journal --my_option barfoobar
# --help
# --verbose help
#
# watch journal with
# $ journalctl -f

import sys
from MythTV import MythLog
from argparse import ArgumentParser

parser = ArgumentParser(usage=" %(prog)s [options]")

parser.add_argument('--my_option', type=str, action="store", dest="my_option",
            help="Specify 'my special option'.")

MythLog.loadArgParse(parser)

try:
    args = parser.parse_args()
except:
    #parser.print_help()
    sys.exit(1)

if args.verbose:
    if args.verbose == 'help':
        print(MythLog.helptext)
        sys.exit(0)

m = MythLog(module = 'test_systemd_journal_logging')

m.log(MythLog.GENERAL, MythLog.DEBUG, 'test my_option: %s' %args.my_option)

"""
The command 'journalctl -f' shows:
test_systemd_journal_argparse.py[6043]: [test_systemd_journal_logging]: test my_option: barfoobar
"""

