#!/usr/bin/python3

import sys
import argparse
import ogGlobals
from SystemLib import ogHelp
from SystemLib import ogRaiseError

if 2 == len (sys.argv) and 'help' == sys.argv[1]:
    #parser.print_help() sale en inglés aunque la locale indique otra cosa
    ogHelp ('ogRaiseError', 'ogRaiseError [str_logfile ...] int_errorcode str_errormessage')
    sys.exit (0)

logtypes = []
while True:
    if sys.argv[1] in ['command', 'log', 'session']:
        logtypes.append (sys.argv.pop (1))
    else: break

parser = argparse.ArgumentParser (add_help=False)
parser.add_argument ('code')
parser.add_argument ('msg')
args = parser.parse_args()

try:
    code = getattr (ogGlobals, args.code)
except AttributeError:
    print (f'unknown code {args.code}')
    sys.exit (1)

ret = ogRaiseError (logtypes, code, args.msg)
if ret is not None:
    if   ret == True: sys.exit (0)
    elif ret == False: sys.exit (1)
