devspace-sh / devspace

DevSpace - The Fastest Developer Tool for Kubernetes ⚡ Automate your deployment workflow with DevSpace and develop software directly inside Kubernetes.
https://devspace.sh
Apache License 2.0
4.37k stars 361 forks source link

devspace completion prints info statement that results in command not found when executed/sourced #1864

Closed matskiv closed 2 years ago

matskiv commented 2 years ago

What happened? Running source <(devspace completion bash) causes the error below:

bash: ommand not found...
bash: 36m[info]: command not found...

This happens when one of the parent folders of the current working directory contains a devspace.yaml file. For me, this happens when I open a new tab or split a terminal in my terminal emulator while in a subfolder of a project that uses devspace.

What did you expect to happen instead? Not printing [info] Using devspace config in ... when running devspace completion, and thus no error message.

How can we reproduce the bug? (as minimally and precisely as possible)

cd /tmp && mkdir test && cd test && touch devspace.yaml && mkdir subfolder && cd subfolder/ && devspace completion bash | head -n 1

You will see [info] Using devspace config in /tmp/test printed. Instead, you should see something like # bash completion for devspace ...

Local Environment:

Workaround: source <(devspace completion bash | grep -v -e "Using devspace config in")

/kind bug

matskiv commented 2 years ago

I had a quick look at the code. The info message in question gets printed by configLoader.SetDevSpaceRoot() that's called from cmd.getCommands() here - https://github.com/loft-sh/devspace/blob/a5eac169596719ace76d4824fb8e1b085581dc25/cmd/run.go#L206 I couldn't quickly come up with an elegant solution that would preserve all other functionality, so I'll probably leave this to folks more familiar with the code base. :)