Skip to content

humility --list-targets fails confusingly when HUMILITY_TARGET is set #597

@hawkw

Description

@hawkw
eliza@jeeves ~ $ export HUMILITY_TARGET='mb-3-sp'
eliza@jeeves ~ $ humility --list-targets
humility: WARNING: archive in environment variable overriding archive in environment file
humility failed: subcommand expected (--help to list)
eliza@jeeves ~ $ unset HUMILITY_TARGET
eliza@jeeves ~ $ humility --list-targets
TARGET          DESCRIPTION
ee-1-sp         EE Station 1 SP
mb-0-sp         Minibar 0's target SP
mb-1-sp         Minibar 1's target SP
mb-2-sp         Minibar 2's target SP
mb-3-sp         Minibar 3's target SP
eliza@jeeves ~ $

I get why it does that: clap interprets the presence of the environment variable as being equivalent to humility --list-targets --target mb-3-sp, which is a nonsensical command line --- the presence of the --target means that it wants a subcommand.

But it feels very weird to me that the same same command line fails or succeeds depending on the env var. I also think the "subcommand expected" error is quite confusing here if you aren't already uncomfortably familiar with how clap's support for environment variables work --- one must understand that it treats HUMILITY_TARGET being set as exactly the same as --target being passed in order to interpret the error message.

Perhaps the best solution here would be to change --list-targets to be list-targets (i.e. a subcommand) instead. It being a flag is a bit odd anyway, since it doesn't make sense to pass --list-targets along with any other subcommand anyway. Weirdly, that does work, which also kind of doesn't make sense:

eliza@jeeves ~ $ humility --list-targets tasks
TARGET          DESCRIPTION
ee-1-sp         EE Station 1 SP
mb-0-sp         Minibar 0's target SP
mb-1-sp         Minibar 1's target SP
mb-2-sp         Minibar 2's target SP
mb-3-sp         Minibar 3's target SP
eliza@jeeves ~ $

it listed targets instead of doing humility tasks...I would have expected this to fail because humility tasks expects a probe, archive, or IP. Which, if you pass that, does make --list-targets break:

eliza@jeeves ~ $ humility --list-targets --target 'mb-3-sp' tasks
error: The argument '--list-targets' cannot be used with:
    --probe <PROBE>
    --dump <DUMP>
    --ip <IP>
    --target <TARGET>

USAGE:
    humility --list-targets --target <TARGET> --archive <ARCHIVE> --environment <ENVIRONMENT>

For more information try --help
eliza@jeeves ~ $

This isn't as bad a UX issue as the confusing error message when run with the env set, but it is a bit odd.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions