make raw yna call redirect to yna ynamazon but without the option to add command-line args#21
make raw yna call redirect to yna ynamazon but without the option to add command-line args#21DanielKarp merged 2 commits intomainfrom
yna call redirect to yna ynamazon but without the option to add command-line args#21Conversation
… to add command-line args
|
@WoosterInitiative could you take a look and let me know what you think? |
|
Clever! I'll do a quick check, but I like it better than I thought I would. |
WoosterInitiative
left a comment
There was a problem hiding this comment.
I know it's being nitpicky and likely doesn't make any difference, but I think I'd prefer this:
from typer import Context
from typer import run as typer_run
from rich import print as rprint
@cli.callback(invoke_without_command=True)
def yna_callback(ctx: Context):
rprint("[bold cyan]Starting YNAmazon processing...[/]"
if ctx.invoked_subcommand is None:
typer_run(ynamazon)Using the renamed "run" and "print" commands are just my preference to avoid having "common" things in my namespace. The print is also just as a clue to the user (me) about what's happening.
Again, it doesn't change the functionality at all, but it seems a little more "native" to Typer and avoids sys.
Either way works, though, choose what makes sense to you.
|
I think that's better. Just a question, does I'll try this out on my local branch and if it works I'll push it to the PR. |
Yes, it behaves exactly as if it had been run as
It seems to treat '--help' with a special case and documents the top-level (showing all of the subcommands). I've played with it a bit and it seems to work as I would expect it to. You can also use the docstring of the callback to say something about running it without any commands or options and it will run ynamazon. I don't have good verbiage in mind, but it might be helpful? |
The reason for not allowing command line args is that it is very hard to do within Typer, as the callback is run every time and it gets messy to figure out if you are running a subcommand or the base command but with args. The apprach I took is to just use a check for the length of
sys.argvto check ifynais being run without any other arguements, and in that case callingynamazonwith the function arguements retrieved from settings directly. Users wanting to use command line args would continue to callyna ynamazon [args]