#!/usr/bin/env python
# SPDX-FileCopyrightText: 2012-2017 Cédric Krier <cedric.krier@b2ck.com>
# SPDX-FileCopyrightText: 2017-2022 Luis Falcón <falcon@gnuhealth.org>
# SPDX-FileCopyrightText: 2017-2022 GNU Solidario <health@gnusolidario.org>
#
# SPDX-License-Identifier: GPL-3.0-or-later

#########################################################################
#   Hospital Management Information System (HMIS) component of the      #
#                       GNU Health project                              #
#                   https://www.gnuhealth.org                           #
#########################################################################
#                      HEALTH WEBDAV SERVER                             #
#              nuhealth-webdav-server: main executable                  #
#########################################################################
import sys
import os
import argparse

DIR = os.path.abspath(os.path.normpath(os.path.join(__file__,
            '..', '..', 'trytond')))
if os.path.isdir(DIR):
    sys.path.insert(0, os.path.dirname(DIR))

from trytond import __version__
from trytond.modules.health_webdav3_server import server


def parse_commandline():
    options = {}

    parser = argparse.ArgumentParser(prog='gnuhealth-webdav-server')

    parser.add_argument('--version', action='version',
        version='%(prog)s ' + __version__)
    parser.add_argument("-c", "--config", dest="configfile", metavar='FILE',
        default=os.environ.get('TRYTOND_CONFIG'), help="specify config file")
    parser.add_argument('--dev', dest='dev', action='store_true',
        help='enable development mode')
    parser.add_argument("-v", "--verbose", action="store_true",
        dest="verbose", help="enable verbose mode")

    parser.add_argument("-d", "--database", dest="database_names", nargs='+',
        default=[], metavar='DATABASE', help="specify the database name")

    parser.add_argument("--pidfile", dest="pidfile", metavar='FILE',
        help="file where the server pid will be stored")
    parser.add_argument("--logconf", dest="logconf", metavar='FILE',
        help="logging configuration file (ConfigParser format)")

    parser.epilog = (
        'The config file can be specified in the TRYTOND_CONFIG '
        'environment variable.\n'
        'The database URI can be specified in the TRYTOND_DATABASE_URI '
        'environment variable.')

    options = parser.parse_args()

    return options

if __name__ == '__main__':
    options = parse_commandline()
    server.GNUHealthWebdavServer(options).run()
