fix(cli): completion requires HCLOUD_TOKEN

The current setup of the CLI requires the user to set HCLOUD_TOKEN for
every single invocation of the binary. Even if we just want to
autocomplete some arguments or even generate the completion scripts in
CI.

This fixes the bug by only initializing the hcloud-go client in the
"cleanup" and "upload" subcommands.
This commit is contained in:
Julian Tölle 2024-05-10 18:03:28 +02:00
parent f7dc501b2f
commit 7881832a54
4 changed files with 17 additions and 6 deletions

View file

@ -23,7 +23,11 @@ $ hcloud ssh-key list -l apricote.de/created-by=hcloud-upload-image
This command does not handle any parallel executions of hcloud-upload-image
and will remove in-use resources if called at the same time.`,
GroupID: "primary",
PreRun: initClient,
RunE: func(cmd *cobra.Command, args []string) error {
ctx := cmd.Context()
logger := contextlogger.From(ctx)