From e89cc6d590690db8c6b77bcd52d36cc68476588f Mon Sep 17 00:00:00 2001 From: Ivan Habunek Date: Tue, 5 Dec 2023 10:45:38 +0100 Subject: [PATCH] Load command defaults from settings --- toot/cli/base.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/toot/cli/base.py b/toot/cli/base.py index c1b0e58..b16cb34 100644 --- a/toot/cli/base.py +++ b/toot/cli/base.py @@ -7,6 +7,7 @@ import typing as t from click.testing import Result from functools import wraps from toot import App, User, config, __version__ +from toot.settings import load_settings if t.TYPE_CHECKING: import typing_extensions as te @@ -31,6 +32,13 @@ def get_default_visibility() -> str: return os.getenv("TOOT_POST_VISIBILITY", "public") +def get_default_map(): + settings = load_settings() + common = settings.get("common", {}) + commands = settings.get("commands", {}) + return {**common, **commands} + + # Tweak the Click context # https://click.palletsprojects.com/en/8.1.x/api/#context CONTEXT = dict( @@ -42,6 +50,8 @@ CONTEXT = dict( max_content_width=100, # Always show default values for options show_default=True, + # Load command defaults from settings + default_map=get_default_map(), )