In Python's Click package, is there any way to treat unknown subcommands as main script's arguments?
Example:
My script has two registered commands: init
and ls
, each accepts their own parameters.
But if I want to call my script without those subcommands, and pass something else to it as the first parameter, I want some general (other) function to fire and process it.
# This would call `init` command with `location=some-location`
./my_script init some-location
# This would call `ls` command with `count=8`
./my_script ls --count 8
# But this should call a separate function with `item=item1`
./myscript item1
Essentially, the desired behaviour is the same as in password-store manager, where there are different commands, but calling pass
with something other than a known command searches for a password.
I researched Click's documentation but did not find any ways to achieve it yet. I tried ignore_unknown_options
or allow_extra_args
, but could not make it work as I'd like.
question from:
https://stackoverflow.com/questions/65938944/click-treat-unknown-subcommand-as-a-parameter 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…