-
Notifications
You must be signed in to change notification settings - Fork 587
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Broken shell completion - Bash #962
Comments
@DanHam we recently merged a PR that addresses this bug. If you run from main (source <(go run cmd/syft/main.go completion bash) there should be no more error. |
Did #965 make its way into v0.48.0 of syft? If so, I'm afraid the issue is still not fixed. $ syft version
Application: syft
Version: 0.45.0
JsonSchemaVersion: 3.2.2
BuildDate: 2022-04-29T15:47:45Z
GitCommit: 36973021fad57baf443ffa88181394b87ce109a0
GitDescription: v0.45.0
Platform: linux/amd64
GoVersion: go1.18.1
Compiler: gc
$ source <(syft completion bash)
complete: usage: complete [-abcdefgjksuv] [-pr] [-DEI] [-o option] [-A action] [-G globpat] [-W wordlist] [-F function] [-C command] [-X filterpat] [-P prefix] [-S suffix] [name ...] While I'm sure the command you posted above works, it requires Go to be installed. The command then downloads may GB's of Go packages and takes many minutes to complete. As such, this is not really a practical solution for many (all?) end users. I'm assuming you meant this as a temporary work around until this is fixed? |
I'm so sorry @DanHam for the miscommunication in my comment. #965 did make it into the latest release. The command run in the above comment was just running syft off of the development branch before compiling. Users should not have to have to have Golang installed to use the program. It looks like the latest release is generating a completion file: When I switch my shell from I also ran the help command and tried out a couple of the different recommendations: The completion file itself being generated does seem to have a few bugs atm and I'll take a look at that portion when I have some more time. It looks like on your end your session is disliking:
complete command output on my current machine
It looks like there might be some disparity between the versions of Running I tried it out by writing a short no-op completion script
^ Same failure you're seeing which I could not replicate on my local OSX distribution. I think the problem is with |
Not a problem. Thank you for taking the time to look into this for us.
Great - hopefully we'll see a fix for this soon. Thanks again for all the time you've spent looking into this (and improving syft in general). |
The : ${PROG:=$(basename ${BASH_SOURCE})} and editing the end with if [[ $(type -t compopt) = "builtin" ]]; then
complete -o default -F __start_ $PROG
else
complete -o default -o nospace -F __start_ $PROG
fi
unset PROG I don't know if it's a problem in github.com/spf13/cobra or with the called options. |
Hi @DanHam, sorry for the very long delay replying to this ticket. Did you happen to see @julien-carsique-sonarsource's comment above with a patch for the completion script? It sounds like the full fix may require a change to the upstream library (cobra) which creates the completion script. Thanks for any updates if you have them! |
Hi @tgerla, I did see the comment and explanation from @julien-carsique-sonarsource - thanks Julien! Rather than installing the completion script in e.g. Following Julien's explanation of the root cause above, I was able to get completions working using the following in my
The sed command just adds 'syft' to the end of the |
Hi @DanHam, thank you for confirming. I think the best thing we can do in the short term is update the documentation with this workaround. We'll go ahead and put this issue in the backlog. Thanks again! |
I'm not sure if At the last block we were talking about above
this is most obvious and leads to the syntax error. But for correctness I guess also all other placed need to be expanded correctly. If I for a short test just hardcode an additional
it looks to me it has some positive effect on properly rendering the Bash shell expansion code. But as said, I'm not a Go developer and do not really see what side-effects and other implications that has. So I'm not really sure what I'm doing, but would suggest to dig in that direction. |
@cschug is 100% right! While our workarounds 'work' they are definitely not the right fix. After reading the comment above I did a bit of testing locally to try and fix this. Although I wouldn't consider myself a Go developer either, everything seemed to be fixed / working as expected so I took the plunge and opened a PR! |
What happened:
I get an error when I attempt to source the generated Bash shell completions:
How to reproduce it (as minimally and precisely as possible):
Anything else we need to know?:
Environment:
syft version
:syft 0.44.1
This also occurs with
0.44.0
and0.43.2
cat /etc/os-release
or similar):The text was updated successfully, but these errors were encountered: