[Python] Can I build a Python Click cli from a config file whos path is itself an argument?

Discussão em 'Python' iniciado por Stack, Junho 16, 2025.

  1. Stack

    Stack Membro Participativo

    Say I have a config file cfg.yaml

    # cfg.yaml
    opt1: "Bailey is the cutest doggo ever!!!"
    opt2: 42


    I would like to dynamically build a cli interface without knowing ahead of time what items are in cfg.yaml. Where the values in the cfg.yaml are the default values of the options. Something like:

    python cli.py config.yaml run --help

    Usage: cli.py run [OPTIONS]

    Options:
    --opt1 TEXT
    --opt2 INTEGER


    Then I could run:

    python cli.py config.yaml run --opt1 my_str --opt2 314159

    Continue reading...

Compartilhe esta Página