vultr / vultr-cli

Official command line tool for Vultr services
Apache License 2.0
478 stars 76 forks source link

[BUG] - CLI requires non-empty VULTR_API_KEY for "help [..]" and "version" subcommands #359

Closed nifr closed 1 year ago

nifr commented 1 year ago

Describe the bug Any of the vultr-cli help [..] subcommands and vultr-cli version ...

... if VULTR_API_KEY is unset or empty string.

Please export your VULTR API key as an environment variable or add `api-key` to your config file, eg:
export VULTR_API_KEY='<api_key_from_vultr_account>'

To Reproduce

  1. Run vultr-cli version
  2. Run vultr-cli help version

Expected behavior

The CLI outputs it's current version or help for the corresponding subcommand.

Vultr-cli v2.18.2

or

Display current version of Vultr-cli

Usage:
  vultr-cli version [flags]

Flags:
  -h, --help   help for version

Global Flags:
      --config string   config file (default is $HOME/.vultr-cli.yaml) (default "/root/.vultr-cli.yaml")

Screenshots Not required.

Desktop (please complete the following information where applicable:

Additional context

Can be worked around as follows:

VULTR_API_KEY='nonemptystring' vultr-cli version
VULTR_API_KEY='nonemptystring' vultr-cli help version
optik-aper commented 1 year ago

@nifr Thanks for the report. This is something that has been on the todo list for a long time. I'll see about adding a patch for these commands at least.

nifr commented 1 year ago

@optik-aper just came back here and I was amazed by your crazy response time.

Thank you so much for the quick response and for looking into this.

I discovered another important sub-command (completion) that fails if VULTR_API_KEY is unset.

source <(vultr-cli completion bash)

Errors out (obviously) as follows:

bash: api-key: command not found
bash: Please: command not found

Note: This also reveals that the error/warning message goes to stdout instead of stderr. Intended?

Current workaround for bash, zsh, [..] for anyone who ends up here until this issue resolved:

if command -v vultr-cli >/dev/null 2>&1; then
  source <(VULTR_API_KEY='workaround' vultr-cli completion "${SHELL##*/}")
fi
optik-aper commented 1 year ago

I appreciate the additional info! I have a working fix on this, but I need to re-organize some of the code to make sure auth-required commands warn the user. Hopefully I'll have some time this week to wrap that part up.

optik-aper commented 1 year ago

Note: This also reveals that the error/warning message goes to stdout instead of stderr. Intended?

I missed this in my first read, sorry. That is how it's currently intended/designed but could be changed. I'll have to think about whether that makes sense to change and try experiments.