spf13/cobra-cli

"Using config file" displays when doing completion command

christianh814 opened this issue · 3 comments

Running

cobra-cli completion bash

Displays

Using config file: ~/.cobra.yaml

This isn't causing an issue, but it's a bit of a cosmetic annoyance, especially since I have source <(cobra-cli completion bash). This text displays every time I open a new terminal tab.

Is there a way to suppress it?

Since this line is printed to stderr, the simplest thing to do is to redirect stderr:
source <(cobra-cli completion bash) 2> /dev/null.

The overall better approach is to avoid sourcing the completion script at every start of the shell. Instead you can store the completion script once in the shell's completion directory. You can run cobra-cli completion bash -h and follow the instructions.

Since this line is printed to stderr, the simplest thing to do is to redirect stderr: source <(cobra-cli completion bash) 2> /dev/null.

This doesn't work

$ source <(cobra-cli completion bash) 2> /dev/null
Using config file: /home/chernand/.cobra.yaml

The overall better approach is to avoid sourcing the completion script at every start of the shell. Instead you can store the completion script once in the shell's completion directory. You can run cobra-cli completion bash -h and follow the instructions.

My preference isn't to load these into a file but instead, load it dynamically. Reason for this is that I don't have to update the completion every time the CLI changes.

Since this line is printed to stderr, the simplest thing to do is to redirect stderr: source <(cobra-cli completion bash) 2> /dev/null.

This doesn't work

Sorry, my mistake. You should use source <(cobra-cli completion bash 2> /dev/null)

My preference isn't to load these into a file but instead, load it dynamically. Reason for this is that I don't have to update the completion every time the CLI changes.

Valid point. For CLIs that are installed with a package manager, this should all be taken care of automatically. But if not, then I understand.