[Python] Click Boolean option can't be required? [duplicate]

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

  1. Stack

    Stack Membro Participativo

    I'm using a click option like this in my code :

    @click.option('--stepids', '-s', required=True, is_flag=True)


    But when I launch my command whithout the -s option, it executes without raising any error. I guess the flag got an implicit value as False, how can I set it to nothing so my script will tell "error missing -s argument" ? I tried default=' ' but it didnt work.

    In case you find it bizarre, I'm using this trick to simulate a multi-value option with an unknown number of arguments.

    @click.option('--stepids', '-s', required=True, is_flag=True)
    @click.argument('stepsids', nargs=-1)


    I can then use it like this "my script -s 10 11 2..."

    Thanks ^^

    Continue reading...

Compartilhe esta Página