trogon icon indicating copy to clipboard operation
trogon copied to clipboard

Taking `default_map` as source of default values into account

Open notniknot opened this issue 2 years ago • 0 comments

When I specify the default parameter in an option, trogon considers this value in the TUI. But when I pass a default_map as part of the context_settings (like shown in the click docs here and here) the option doesn't get prefilled.

This behaviour might be misleading because an existing default_map overwrites an options default value. Thus, the application actually runs with a different option value than trogon suggested.

Consider the following code:

import click
from trogon import tui


@tui(command="ui", help="Open terminal UI")
@click.group()
def cli():
    pass


@cli.command()
@click.option("--port", default=8000, show_default=True)
def runserver(port):
    click.echo(f"Serving on http://127.0.0.1:{port}/")


if __name__ == "__main__":
    cli(default_map={"runserver": {"port": 5000}})

The runserver sub-command actually runs with port 5000 because of the default_map. But trogon prefills the textbox in the TUI with port 8000, which is wrong.

notniknot avatar Jul 22 '23 08:07 notniknot