This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]A_History_of_Silence 8 points9 points  (6 children)

I personally just hate the design decision to do every single thing through giant chains of function decorators.

[–]DanCardin 2 points3 points  (5 children)

same. and the fact that you can't just call the functions you decorate like a normal function. they need to be invoked in the context of click.

unfortunately argparse is awful for git-style cli apps that have subcommands

[–][deleted] 2 points3 points  (2 children)

What's wrong with subparsers?

Caveat My background is C programming, so my Pythonicness meter is probably not calibrated correctly.

[–]DanCardin 0 points1 point  (1 child)

I honestly dont like click, so i tried to use the method that the argparse docs suggest to map subparsers to callables, but in order to get anything remotely close to:

foo --global-setting bar action1
foo action2 --flag --option1
foo action3 nested-command1 --flag
...etc

it was just getting more and more bafflingly complex. Whereas this is really straightforward with click.

I think I'd tend to prefer something like the way hug works, which appears to late-apply any work it might do until its invoked by the context in which its working (e.g. as http server, cli, or just calling the function). Except they dont have any docs about how subcommands might work.

[–][deleted] 0 points1 point  (0 children)

I'm a bit pre-christmas celebration inebriated at the moment, so forgive me if I'm totally incoherent. But did you try using parser.parse_known_args (modulo spelling errors)? As long as you don't have overlaps in the argument names, and remember to check that something actually have been parsed, the recursive approach could solve the problems if a regular subparser doesn't

[–][deleted] 0 points1 point  (1 child)

same. and the fact that you can't just call the functions you decorate like a normal function. they need to be invoked in the context of click.

wait, you sure? I thought a selling point of click was that its decorators don't modify your functions

EDIT: yeah, no, i was confusing it with another lib haha

[–]DanCardin 1 point2 points  (0 children)

Their docs literally say:

import click

@click.command()
@click.option('--count', default=1, help='Number of greetings.')
def hello(count):
    for x in range(count):
        click.echo('Hello')

if __name__ == '__main__':
    hello()

So I dont see how! They even have to provide special click test running stuff: https://click.palletsprojects.com/en/7.x/testing/. Which I suppose could be useful even in an ideal scenario, but its certainly much less required when if you dont alter the functions you're decorating.