pmb.helpers.frontend.config: add option to reset config to default (!1907)

This commit is contained in:
Niklas Cathor 2020-04-06 15:47:13 +02:00 committed by Alexey Min
parent 00a4eaf91d
commit 29a3cb2b8c
No known key found for this signature in database
GPG Key ID: EBF5ECFFFEE34DED
2 changed files with 10 additions and 1 deletions

View File

@ -140,7 +140,14 @@ def config(args):
raise RuntimeError("Invalid config key: " + args.name)
cfg = pmb.config.load(args)
if args.value is not None:
if args.reset:
if args.name is None:
raise RuntimeError("config --reset requires a name to be given.")
value = pmb.config.defaults[args.name]
cfg["pmbootstrap"][args.name] = value
logging.info("Config changed to default: " + args.name + "='" + value + "'")
pmb.config.save(args, cfg)
elif args.value is not None:
cfg["pmbootstrap"][args.name] = args.value
logging.info("Config changed: " + args.name + "='" + args.value + "'")
pmb.config.save(args, cfg)

View File

@ -603,6 +603,8 @@ def arguments():
# Action: config
config = sub.add_parser("config",
help="get and set pmbootstrap options")
config.add_argument("-r", "--reset", action="store_true",
help="Reset config options with the given name to it's default.")
config.add_argument("name", nargs="?", help="variable name, one of: " +
", ".join(sorted(pmb.config.config_keys)),
choices=pmb.config.config_keys, metavar="name")