[core] Change OptionParser to ArgumentParser

This commit is contained in:
Martin Rey 2020-07-09 15:11:26 +02:00 committed by Thomas Lindner
parent d1d710e05e
commit 8a32a80480
2 changed files with 13 additions and 5 deletions

View file

@ -1,6 +1,7 @@
Copyright (C) 2020 by Thomas Lindner <tom@dl6tom.de> Copyright (C) 2020 by Thomas Lindner <tom@dl6tom.de>
Copyright (C) 2020 by Cathy Hu <cathy.hu@fau.de> Copyright (C) 2020 by Cathy Hu <cathy.hu@fau.de>
Copyright (C) 2020 by Christian <c.hagenest@pm.me> Copyright (C) 2020 by Christian <c.hagenest@pm.me>
Copyright (C) 2020 by Martin Rey <martin.rey@mailbox.org>
Permission to use, copy, modify, and/or distribute this software for any purpose Permission to use, copy, modify, and/or distribute this software for any purpose
with or without fee is hereby granted. with or without fee is hereby granted.

View file

@ -1,9 +1,10 @@
# Copyright (C) 2020 by Thomas Lindner <tom@dl6tom.de> # Copyright (C) 2020 by Thomas Lindner <tom@dl6tom.de>
# Copyright (C) 2020 by Cathy Hu <cathy.hu@fau.de> # Copyright (C) 2020 by Cathy Hu <cathy.hu@fau.de>
# Copyright (C) 2020 by Martin Rey <martin.rey@mailbox.org>
# #
# SPDX-License-Identifier: 0BSD # SPDX-License-Identifier: 0BSD
from optparse import OptionParser from argparse import ArgumentParser
from pytoml import load from pytoml import load
@ -13,12 +14,18 @@ config = {
'root_url': 'http://localhost:8000/', 'root_url': 'http://localhost:8000/',
} }
parser = OptionParser() parser = ArgumentParser()
parser.add_option('-f', dest='configfile', default='/etc/kibicara.conf') parser.add_argument(
(option, args) = parser.parse_args() '-f',
'--config',
dest='configfile',
default='/etc/kibicara.conf',
help='path to config file',
)
args = parser.parse_args()
try: try:
with open(option.configfile) as configfile: with open(args.configfile) as configfile:
config.update(load(configfile)) config.update(load(configfile))
except FileNotFoundError: except FileNotFoundError:
# run with default config # run with default config