From af05e0927fc864fca950cea986c4805a1aa7eec7 Mon Sep 17 00:00:00 2001 From: matejcik Date: Mon, 23 Mar 2020 13:09:26 +0100 Subject: [PATCH] python/trezorctl: nicer output for list-devices --- python/src/trezorlib/cli/trezorctl.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/python/src/trezorlib/cli/trezorctl.py b/python/src/trezorlib/cli/trezorctl.py index 3596e742f3..99bfb51e39 100755 --- a/python/src/trezorlib/cli/trezorctl.py +++ b/python/src/trezorlib/cli/trezorctl.py @@ -203,15 +203,29 @@ def print_result(res, is_json, **kwargs): click.echo(res) +def format_device_name(features): + model = features.model or "1" + if features.bootloader_mode: + return "Trezor {} bootloader".format(model) + + label = features.label or "(unnamed)" + return "{} [Trezor {}, {}]".format(label, model, features.device_id) + # # Common functions # @cli.command(name="list") -def list_devices(): +@click.option("-n", "no_resolve", is_flag=True, help="Do not resolve Trezor names") +def list_devices(no_resolve): """List connected Trezor devices.""" - return enumerate_devices() + if no_resolve: + return enumerate_devices() + + for transport in enumerate_devices(): + client = TrezorClient(transport, ui=ui.ClickUI()) + click.echo("{} - {}".format(transport, format_device_name(client.features))) @cli.command()