Skip to content
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

Add bash and zsh completion scripts for openqa-cli #6063

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

b10n1k
Copy link
Contributor

@b10n1k b10n1k commented Nov 19, 2024

  • Allow static completion of the openqa-cli
  • Provide full cli options for each subcommand
  • Group options for each subcommand
  • Not help text in bash due to compgen function doesn't support descriptions

Copy link
Contributor

@perlpunk perlpunk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only thing I don't like is the duplication. We would have the parameters now in four places:

There is a solution for that, but it is a bigger change, not sure if we want that here.

I wrote a program that can create pod and completion scripts from a YAML file.
The openqa-cli code could also read the YAML file, so we would only have the parameters in one place.
But it would be a new dependency, at least for developers.
(One cool thing is that it can generate completion with descriptions also for bash, with a trick)

I could at least post a proof of concept.

@perlpunk
Copy link
Contributor

I could at least post a proof of concept.

https://gist.github.com/perlpunk/b0d9fe14f3c877f28d8af3db6be28c70
Here is the demo with the bash completion including descriptions:
https://gist.github.com/perlpunk/b0d9fe14f3c877f28d8af3db6be28c70#file-demo-txt

@b10n1k
Copy link
Contributor Author

b10n1k commented Nov 20, 2024

The only thing I don't like is the duplication. We would have the parameters now in four places:

There is a solution for that, but it is a bigger change, not sure if we want that here.

I wrote a program that can create pod and completion scripts from a YAML file. The openqa-cli code could also read the YAML file, so we would only have the parameters in one place. But it would be a new dependency, at least for developers. (One cool thing is that it can generate completion with descriptions also for bash, with a trick)

I could at least post a proof of concept.

awesome and thanks for taking the time for the proof of concept.
in general, this was one idea for the hackweek, and learning stuff for me. I know that ideally it should be automatic in some way, but it was easier for me to provide something within the hackweek, and thats why I keep it as simple as possible. Not sure I am going to do the automation, as I believe is on another level for me and my plan is to look at another small project I am interested in. I hope we are not gonna be too restrict with this PR for now. It is so cool to have it and I have also additional ideas for it.
So manybe we could open some backlog tickets for the rest? wdyt?

@perlpunk
Copy link
Contributor

I would say, at least make it installable like discussed in this thread #6063 (comment)
And the files shouldn't be in the toplevel directory anyway, I think.

Copy link
Contributor

@Martchus Martchus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not nice that we not only introduce one more place where we specify arguments but even two. Ideally we have a single source of truth. That would of course complicate things. Maybe we can make it so there's at least just one additional place where we specify arguments.

The code that does the argument parsing definitely needs to state in a comment that one also has to change these files when adding new parameters or changing help texts.

Copy link

Great PR! Please pay attention to the following items before merging:

Files matching docs/*.asciidoc:

  • Consider generating documentation locally to verify it is rendered correctly using tools/generate-docs

This is an automatically generated QA checklist based on modified files.

Copy link
Member

@okurz okurz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Considering that @perlpunk already provided a proof of concept to reduce duplication with #6063 (comment) we should follow that approach

dist/rpm/openQA.spec Outdated Show resolved Hide resolved
dist/rpm/openQA.spec Outdated Show resolved Hide resolved
@b10n1k b10n1k force-pushed the autocompletion_cli branch 5 times, most recently from dc3d9dc to f75305f Compare November 22, 2024 08:11
dist/rpm/openQA.spec Outdated Show resolved Hide resolved
@b10n1k b10n1k force-pushed the autocompletion_cli branch 3 times, most recently from 6028003 to 95f0df9 Compare November 22, 2024 17:15
dist/rpm/openQA.spec Outdated Show resolved Hide resolved
@@ -0,0 +1,37 @@
#!/usr/bin/env bash
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would still prefer a more generic directory name. We don't want to create a top level subfolder for every kind of feature we add.
I suggest either share/completion , or we use the existing contrib directory, so contrib/completion.
Other opinions?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

contrib/completion seems like a nice place

Comment on lines 437 to 438
install -Dm 0644 completion/openqa-cli-completion.bash %{buildroot}%{_datadir}/openqa/completion/openqa-cli-completion.bash
install -Dm 0644 completion/openqa-cli-completion.zsh %{buildroot}%{_datadir}/openqa/completion/openqa-cli-completion.zsh
Copy link
Contributor

@perlpunk perlpunk Nov 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should do it, haven't tested it yet:

Suggested change
install -Dm 0644 completion/openqa-cli-completion.bash %{buildroot}%{_datadir}/openqa/completion/openqa-cli-completion.bash
install -Dm 0644 completion/openqa-cli-completion.zsh %{buildroot}%{_datadir}/openqa/completion/openqa-cli-completion.zsh
install -D -m 0644 %{_sourcedir}/contrib/completion/openqa-cli-completion.bash %{buildroot}%{_datadir}/bash-completion/completions/openqa-cli
install -D -m 0644 %{_sourcedir}/contrib/completion/openqa-cli-completion.zsh %{buildroot}%{_datadir}/zsh/site-functions/_openqa-cli
# ...
# later
%files client-bash-completion
%{_datadir}/bash-completion/completions/openqa-cli
%files client-zsh-completion
%{_datadir}/zsh

* Allow static completion of the openqa-cli
* Provide full cli options for each subcommand
* Group options for each subcommand
* Not help text in bash due to `compgen` function doesn't support descriptions

Signed-off-by: Ioannis Bonatakis <[email protected]>
@b10n1k b10n1k force-pushed the autocompletion_cli branch 5 times, most recently from a37aad3 to ca87c8a Compare November 26, 2024 07:54
@@ -419,6 +434,8 @@ done
#
install -D -m 644 /dev/null %{buildroot}%{_localstatedir}/log/openqa
install -m 0644 %{_sourcedir}/openQA.changes %{buildroot}%{_datadir}/openqa/public/Changelog
install -Dm 0644 completion/openqa-cli-completion.bash %{buildroot}%{_datadir}/bash-completion/completions/openqa-cli
install -Dm 0644 completion/openqa-cli-completion.zsh %{buildroot}%{_datadir}/usr/share/zsh/site-functions/_openqa-cli
Copy link
Contributor

@perlpunk perlpunk Nov 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There was a reason I used %{_sourcedir} in my suggestion.

Hint: look a little bit up in line 426 cd %{buildroot}. At that point we are not in the source dir anymore.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[   42s] + install -Dm 0644 /home/abuild/rpmbuild/SOURCEScompletion/openqa-cli-completion.bash /home/abuild/rpmbuild/BUILDROOT/openQA-4.6.1732626492.73cf032a-7440.1.x86_64/usr/share/bash-completion/completions/openqa-cli
[   42s] install: cannot stat '/home/abuild/rpmbuild/SOURCEScompletion/openqa-cli-completion.bash': No such file or directory

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apart from missing a slash, now I think _sourcedir might not be the directory we want here.
Try it out by adding the slash.
Otherwise you can just move those statements up before the cd statement.

@b10n1k b10n1k force-pushed the autocompletion_cli branch 2 times, most recently from 73cf032 to e511759 Compare November 26, 2024 19:11
Provide openqa-cli bash completion for openqa-cli as a package when openQA is
install and bash is used.

Signed-off-by: Ioannis Bonatakis <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants