allow loading config files in TOML format with --config-toml
This commit is contained in:
@@ -72,9 +72,11 @@
|
||||
--no-check-certificate Disable HTTPS certificate validation
|
||||
|
||||
## Configuration Options:
|
||||
-o, --option KEY=VALUE Additional options. Example: -o browser=firefox
|
||||
-c, --config FILE Additional configuration files
|
||||
-o, --option OPT Additional '<key>=<value>' option values
|
||||
--ignore-config Do not read default configuration files
|
||||
--config-yaml FILE Additional configuration files in YAML format
|
||||
--config-toml FILE Additional configuration files in TOML format
|
||||
--config-ignore Do not read default configuration files
|
||||
|
||||
## Authentication Options:
|
||||
-u, --username USER Username to login with
|
||||
|
||||
@@ -40,10 +40,12 @@ def main():
|
||||
# configuration
|
||||
if args.load_config:
|
||||
config.load()
|
||||
if args.cfgfiles:
|
||||
config.load(args.cfgfiles, strict=True)
|
||||
if args.yamlfiles:
|
||||
config.load(args.yamlfiles, strict=True, fmt="yaml")
|
||||
if args.configs_json:
|
||||
config.load(args.configs_json, strict=True)
|
||||
if args.configs_yaml:
|
||||
config.load(args.configs_yaml, strict=True, fmt="yaml")
|
||||
if args.configs_toml:
|
||||
config.load(args.configs_toml, strict=True, fmt="toml")
|
||||
if args.filename:
|
||||
filename = args.filename
|
||||
if filename == "/O":
|
||||
|
||||
@@ -58,6 +58,17 @@ def load(files=None, strict=False, fmt="json"):
|
||||
except ImportError:
|
||||
log.error("Could not import 'yaml' module")
|
||||
return
|
||||
elif fmt == "toml":
|
||||
try:
|
||||
import tomllib
|
||||
load = tomllib.loads
|
||||
except ImportError:
|
||||
try:
|
||||
import toml
|
||||
load = toml.loads
|
||||
except ImportError:
|
||||
log.error("Could not import 'toml' module")
|
||||
return
|
||||
else:
|
||||
load = util.json_loads
|
||||
|
||||
|
||||
@@ -320,15 +320,26 @@ def build_parser():
|
||||
)
|
||||
|
||||
configuration = parser.add_argument_group("Configuration Options")
|
||||
configuration.add_argument(
|
||||
"-o", "--option",
|
||||
dest="options", metavar="KEY=VALUE", action=ParseAction, default=[],
|
||||
help=("Additional options. "
|
||||
"Example: -o browser=firefox") ,
|
||||
)
|
||||
configuration.add_argument(
|
||||
"-c", "--config",
|
||||
dest="cfgfiles", metavar="FILE", action="append",
|
||||
dest="configs_json", metavar="FILE", action="append",
|
||||
help="Additional configuration files",
|
||||
)
|
||||
configuration.add_argument(
|
||||
"--config-yaml",
|
||||
dest="yamlfiles", metavar="FILE", action="append",
|
||||
help=argparse.SUPPRESS,
|
||||
dest="configs_yaml", metavar="FILE", action="append",
|
||||
help="Additional configuration files in YAML format",
|
||||
)
|
||||
configuration.add_argument(
|
||||
"--config-toml",
|
||||
dest="configs_toml", metavar="FILE", action="append",
|
||||
help="Additional configuration files in TOML format",
|
||||
)
|
||||
configuration.add_argument(
|
||||
"--config-ignore",
|
||||
@@ -340,11 +351,6 @@ def build_parser():
|
||||
dest="load_config", action="store_false",
|
||||
help=argparse.SUPPRESS,
|
||||
)
|
||||
configuration.add_argument(
|
||||
"-o", "--option",
|
||||
dest="options", metavar="OPT", action=ParseAction, default=[],
|
||||
help="Additional '<key>=<value>' option values",
|
||||
)
|
||||
|
||||
authentication = parser.add_argument_group("Authentication Options")
|
||||
authentication.add_argument(
|
||||
|
||||
Reference in New Issue
Block a user