Nitrokey / pynitrokey

Python client for Nitrokey devices
Apache License 2.0
100 stars 27 forks source link

[0.6.0] strange error on update when more the one device are connected. #578

Open mdc-webdb opened 3 weeks ago

mdc-webdb commented 3 weeks ago

All call of nitropy nk3 update fails with:

nitropy nk3 update Command line tool to interact with Nitrokey devices 0.6.0 Critical error: Multiple NK3 devices found -- use the --path option to select one

This line is not very informative, because nitropy nk3 list

nitropy nk3 list Command line tool to interact with Nitrokey devices 0.6.0 :: 'NK3' keys /dev/hidraw0: Nitrokey 3 YYYY /dev/hidraw1: Nitrokey 3 ZZZZ

will show all, but the path option fails on the update command.

nitropy nk3 update --help Command line tool to interact with Nitrokey devices 0.6.0 Usage: nitropy nk3 update [OPTIONS] [IMAGE]

So the "path" will be the first option. But it will fails with:

nitropy nk3 update --path /dev/hidraw1
Command line tool to interact with Nitrokey devices 0.6.0
Usage: nitropy nk3 update [OPTIONS] [IMAGE]
Try 'nitropy nk3 update -h' for help.

Error: No such option: --path
robin-nitrokey commented 3 weeks ago

The following command should work:

$ nitropy nk3 --path /dev/hidraw1 update

I understand that this can be very confusing. AFAIK this is a limitation of the CLI framework we use because the --path option is defined for all Nitrokey 3 commands. I don’t know a way to make nitropy nk3 update --path /dev/hidraw1 work without manually duplicating the option for all commands. But at least we could update the error message with an example invocation that shows the correct call.

robin-nitrokey commented 3 weeks ago

Here’s the upstream issue: https://github.com/pallets/click/issues/66. There is no intention to change the behavior. We could try to work around it as described here: https://stackoverflow.com/questions/32493912/is-it-possible-to-add-a-global-argument-for-all-subcommands-in-click-based-inter

mdc-webdb commented 3 weeks ago

Hi @robin-nitrokey, I think an better message with an example in the error message will be the best. Because here the code change will be very simple.