From b84b0a6eedfcf4ea2b1fae160783b04b5fc86e1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Behmo?= Date: Mon, 18 Mar 2019 22:38:13 +0100 Subject: [PATCH] Add convenient "config printvalue" command --- CHANGELOG.md | 1 + tutor/config.py | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d009c52..5012fd8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ## Latest +- [Feature] Add convenient `config printvalue` command - [Feature] Customize docker registry - [Feature] Load configuration parameters from the system environment - [Improvement] Automatic environment re-generation after re-configuration diff --git a/tutor/config.py b/tutor/config.py index 5fa60f4..77aadfe 100644 --- a/tutor/config.py +++ b/tutor/config.py @@ -42,6 +42,18 @@ def save(root, silent, set_): def printroot(root): click.echo(root) +@click.command(help="Print a configuration value") +@opts.root +@click.argument("key") +def printvalue(root, key): + config = {} + load_current(config, root) + load_defaults(config) + try: + print(config[key]) + except KeyError: + raise exceptions.TutorError("Missing configuration value: {}".format(key)) + def load(root): """ Load configuration, and generate it interactively if the file does not @@ -200,3 +212,4 @@ def config_path(root): config.add_command(save) config.add_command(printroot) +config.add_command(printvalue)