-
Notifications
You must be signed in to change notification settings - Fork 18
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
Fix/bash completion #38
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR 👍 I have few questions, comments and requests.
Makefile
Outdated
@@ -126,6 +127,7 @@ install: $(BIN) $(DATA) | |||
install -D -m755 ./rhc $(DESTDIR)$(BINDIR)/$(SHORTNAME) | |||
install -D -m644 ./rhc.1.gz $(DESTDIR)$(MANDIR)/man1/$(SHORTNAME).1.gz | |||
install -D -m644 ./rhc.bash $(DESTDIR)$(DATADIR)/bash-completion/completions/$(SHORTNAME) | |||
install -D -m644 ./rhc.bash $(DESTDIR)$(DATADIR)/bash-completion/completions/$(SHORTNAME)d |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would not do it in this way. This is upstream repository for rhc client. We should not have here any changes that are specific for downstream. The upstream repository of rhcd is yggdrasil. Thus I would just not add this line to this patch.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should introduce similar change to yggdrasil upstream repository. Note: yggdrasil uses meson build system.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I did not know this! Thx!
urfave_cli_path.sh
Outdated
|
||
URFAVECLI_PATH="$GOMODCACHE/${URFAVECLI_VER[0]}@${URFAVECLI_VER[1]}" | ||
|
||
echo "$URFAVECLI_PATH" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that it is not necessary to have special file with this script, because it is used only in Makefile
.
Or is this script useful for anything else?
If not, then I think that we should "move" the whole script (or the logic of the script) into the Makefile
.
Reference: https://www.gnu.org/software/make/manual/html_node/One-Shell.html
Makefile
Outdated
%.bash: $(GOSRC) | ||
go run $(BUILDFLAGS) -ldflags "$(LDFLAGS)" . --generate-bash-completion > $@ | ||
cp $(URFAVECLI_PATH)/autocomplete/bash_autocomplete $@ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it actually necessary to use the latest version of the bash script from urfave
Go package? The script is very simple:
#! /bin/bash
: ${PROG:=$(basename ${BASH_SOURCE})}
_cli_bash_autocomplete() {
if [[ "${COMP_WORDS[0]}" != "source" ]]; then
local cur opts base
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
if [[ "$cur" == "-"* ]]; then
opts=$( ${COMP_WORDS[@]:0:$COMP_CWORD} ${cur} --generate-bash-completion )
else
opts=$( ${COMP_WORDS[@]:0:$COMP_CWORD} --generate-bash-completion )
fi
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
return 0
fi
}
complete -o bashdefault -o default -o nospace -F _cli_bash_autocomplete $PROG
unset PROG
Couldn't we just copy the script to our repository? I'm not enforcing. I'm just asking :-).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I've later discussed as better option to have the script included directly exactly because it is simple and probably will not be changed in future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. I have only small request. Can you please rebase and squash 8 commits into one commit?
There are many pages how to do that. E.g. here: https://stackoverflow.com/questions/5189560/how-do-i-squash-my-last-n-commits-together
I do usually this:
git reset --soft HEAD~<num_of_commits_to_be_squashed>
git commit
git push --force origin <current_branch>
You can also extend git commit
with --reedit-message=<commit_hash>
, when you already has some good commit message and you don't want to write commit message again.
Note: We will have to do another improvement in another PR after this PR will be merged. IMHO It will be also necessary to adjust https://github.com/RedHatInsights/rhc/blob/main/util.go#L52, because bash completion script suggest hidden command line options and it is not want we want, because these hidden command line option are not documented and it could be confusing. Hidden command line options are intended only for testing purpose. |
8132031
to
0b7caf1
Compare
…hc project dir as rhc.bash Makefile fix to generate correct 'rhc.bash' file. Signed-off-by: Martin Grunwald <mgrunwal@redhat.com> Signed-off-by: grunwmar <mgrunwal@redhat.com> Approach changed to get correct urfave/cli version by grepping it from go.mod Signed-off-by: grunwmar <mgrunwal@redhat.com> Previous extraction of autocomplete bash script from go 'urfave/cli' package was replaced by direct inserting the autocompletion script to the RHC project directory. Previous extraction of autocomplete bash script from go 'urfave/cli' package was replaced by direct inserting the autocompletion script to the RHC project directory. fix: Autocompletion script from 'urfave/cli' was directly placed to rhc project dir as rhc.bash Makefile fix to generate correct 'rhc.bash' file. Signed-off-by: Martin Grunwald <mgrunwal@redhat.com> Signed-off-by: grunwmar <mgrunwal@redhat.com> readded rhc.bash to .gitignore Making rhcd copletion file removed from automake Signed-off-by: grunwmar <mgrunwal@redhat.com> Readded rhc.bash script Readded rhc.bash script Signed-off-by: grunwmar <mgrunwal@redhat.com> Removed old var from Makefile Signed-off-by: grunwmar <mgrunwal@redhat.com>
0b7caf1
to
bc701b7
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. I think we can merge it as it is.
LGTM. This is similar to how I corrected it in yggdrasil: RedHatInsights/yggdrasil@eebef45 |
Bash completion of rhc does not work (RHELPLAN-140295)
[GitHub grunwmar repo/branch rhc/fix/bash-completion]
Bugzilla link: https://bugzilla.redhat.com/show_bug.cgi?id=2145198
I hope the text is understandable. Excuseme for quite verbose style, however as many of us are not native speakers of English I just want to be sure that all things are explained and understood well.
Analysis
Urfave/cli
urfave/cli
package exports apps subcommands and options as a textual list tostdout
defined inside instance of itscli.App
.--generate-bash-completion
which exports the list tostdout
.urfave/cli
package there is predefined bash scripturfave/cli/<version>/autocomplete/bash_autocomplete
which does proper autocompletion using call of the app with the mentioned--generate-bash-completion
option, so the script can get subcommands and options to show (the autocompletion calls the app with mentioned option everytime thetab
key is pressed to obtain autocompletion)./usr/share/bash-completion/completions/<app_name>
. Theurfave/cli
will not to do it by itself (see documentation).go
packageurfave/cli/<version>/autocomplete/bash_autocomplete
with correctly definedPROG
environmental variable in shell session (described later in Summary/Another approach section).bash-autocompletion
(just bydnf install bash-completion
).RHC
Makefile
creates a filerhc.bash
containing list of subcommands/option for autocompletion by runningrhc --generate-bash-completion > rhc.bash
(github). But it means that filerhc.bash
is not a bash script indeed. Then this file is delivered to the destination where the autoclompletion script should be i.e. to/usr/share/bash-completion/completions/
. And of course the corresponding file forrhcd
command is somewhere on Arrakis.Makefile
makes and places to directory containing autocompletions a nonsense, but not the autocompletion script forrhc
andrhcd
commands.rhc/main: Makefile [row 90]
rhc/main: Makefile [row 128]
Solution seems to be simple. Just to take file from
urfave/cli/<version>/autocomplete/bash_autocomplete
and copy it to/usr/share/bash-completion/completions/
two-times. Once asrhc
once asrhcd
. Then all works nicely (ifbash-completion
are installed).Solution
I choose approach to just place the file
urfave/cli/<version>/autocomplete/bash_autocomplete
to rhc project asrhc.bash
and removing corresponding part ofMakefile
(rhc/main: Makefile [row 89]
).Summary
I am not fully satisfied with this solution, mainly because the
urfave_cli_path.sh
script I added has to be marked as executable. I found, thatUrfave/cli.App
loads information about the path to isbash_autocomplete
toApp
object, but this variable is not exposed and I was unable to reach it fromrhc
code, although to be able to get the path direclty fromUrfave/cli.App
instance would be much much nicer way to solve the problem.Another approach
using
still requres the fill the correct
<verstion>
placeholder and therefore usage of something likeurfave_cli_path.sh
, i.e. still is needed to get correct path to thebash_autocomplete
file.Another minor issue is, that when running
make install
the command is complaining about missingdbus-1
package:This could be easily fixed by running
dnf install dbus-devel
.