From d52a34ff9bbbfa96f0e1df4be4754c3dde2f2aa5 Mon Sep 17 00:00:00 2001 From: Ioannis Bonatakis Date: Thu, 21 Nov 2024 16:00:32 +0100 Subject: [PATCH] Create openqa-cli-bash-completion package Provide openqa-cli bash completion for openqa-cli as a package when openQA is install and bash is used. Signed-off-by: Ioannis Bonatakis Signed-off-by: ybonatakis Signed-off-by: Ioannis Bonatakis Signed-off-by: ybonatakis --- Makefile | 11 +++++++++ .../completions/openqa-cli-completion.bash | 2 -- .../completions/openqa-cli-completion.zsh | 6 ++--- dist/rpm/openQA.spec | 23 +++++++++++++++++++ docs/UsersGuide.asciidoc | 10 +++----- 5 files changed, 40 insertions(+), 12 deletions(-) rename openqa-cli-completion.bash => contrib/completions/openqa-cli-completion.bash (98%) rename openqa-cli-completion.zsh => contrib/completions/openqa-cli-completion.zsh (94%) diff --git a/Makefile b/Makefile index e370a597a23..5f4cb20cb8a 100644 --- a/Makefile +++ b/Makefile @@ -125,6 +125,17 @@ install-generic: ln -s ../postgresql.service "$(DESTDIR)"/usr/lib/systemd/system/openqa-scheduler.service.requires/postgresql.service install -d -m 755 "$(DESTDIR)"/usr/lib/systemd/system/openqa-websockets.service.requires ln -s ../postgresql.service "$(DESTDIR)"/usr/lib/systemd/system/openqa-websockets.service.requires/postgresql.service + install -D -m 644 contrib/completions/openqa-cli-completion.bash "$(DESTDIR)"/usr/share//bash-completion/completions/openqa-cli + install -D -m 644 contrib/completions/openqa-cli-completion.zsh "$(DESTDIR)"/usr/share/zsh/site-functions/_openqa-cli + if [ "$(SHELL)" = "/bin/bash" ] || [ "$(SHELL)" = "/usr/bin/bash" ]; then \ + echo "source $(DESTDIR)/usr/share/bash-completion/completions/openqa-cli" >> "$(HOME)/.bashrc"; \ + elif [ "$(SHELL)" = "/bin/zsh" ] || [ "$(SHELL)" = "/usr/bin/zsh" ]; then \ + echo "fpath+=($(DESTDIR)/usr/share/zsh/site-functions)" >> "$(HOME)/.zshrc"; \ + echo "autoload -Uz compinit && compinit" >> "$(HOME)/.zshrc"; \ + else \ + echo "Unsupported shell: $(SHELL). Skipping completion setup."; \ + fi + # # install openQA apparmor profile install -d -m 755 "$(DESTDIR)"/etc/apparmor.d diff --git a/openqa-cli-completion.bash b/contrib/completions/openqa-cli-completion.bash similarity index 98% rename from openqa-cli-completion.bash rename to contrib/completions/openqa-cli-completion.bash index 9b3bc32619e..c2eecc6d5ec 100644 --- a/openqa-cli-completion.bash +++ b/contrib/completions/openqa-cli-completion.bash @@ -1,5 +1,3 @@ -#!/usr/bin/env bash - _openqa_cli_completions() { local cur prev subcommands main_options api_options archive_options monitor_options schedule_options cur="${COMP_WORDS[COMP_CWORD]}" diff --git a/openqa-cli-completion.zsh b/contrib/completions/openqa-cli-completion.zsh similarity index 94% rename from openqa-cli-completion.zsh rename to contrib/completions/openqa-cli-completion.zsh index 287d0185b13..f0f33efcc6c 100644 --- a/openqa-cli-completion.zsh +++ b/contrib/completions/openqa-cli-completion.zsh @@ -1,4 +1,4 @@ -#!/usr/bin/env zsh +#compdef openqa-cli _openqa_cli_completions() { local curcontext="$curcontext" state line @@ -62,10 +62,10 @@ _openqa_cli_completions() { _arguments '*:option:->options' $main_options $archive_options ;; monitor) - _arguments '*:option:->options' $main_options $archive_options + _arguments '*:option:->options' $main_options $monitor_options ;; schedule) - _arguments '*:option:->options' $main_options $archive_options + _arguments '*:option:->options' $main_options $schedule_options ;; *) _values 'subcommand' api archive monitor schedule diff --git a/dist/rpm/openQA.spec b/dist/rpm/openQA.spec index 1af37ecb2c5..d6a0d5bbd05 100644 --- a/dist/rpm/openQA.spec +++ b/dist/rpm/openQA.spec @@ -314,6 +314,20 @@ Use this package to install munin scripts that allow to monitor some openQA statistics. %endif +%package client-bash-completion +Summary: Bash Completion for %{name} +Requires: bash-completion +Supplements: (%{name}-client and bash) + +%description client-bash-completion +The official bash completion script for openqa-cli. + +%package client-zsh-completion +Summary: Zsh Completion for %{name} +Supplements: (%{name}-client and zsh) + +%description client-zsh-completion +The official zsh completion script for openqa-cli. %prep %setup -q @@ -408,6 +422,10 @@ install -m 644 contrib/munin/config/minion.config %{buildroot}/%{_sysconfdir}/mu install -m 755 contrib/munin/utils/munin-mail %{buildroot}/%{_datadir}/openqa/script/munin-mail %endif +# completion +install -Dm 0644 contrib/completions/openqa-cli-completion.bash %{buildroot}%{_datadir}/bash-completion/completions/openqa-cli +install -Dm 0644 contrib/completions/openqa-cli-completion.zsh %{buildroot}%{_datadir}/zsh/site-functions/_openqa-cli + cd %{buildroot} grep -rl %{_bindir}/env . | while read file; do sed -e 's,%{_bindir}/env perl,%{_bindir}/perl,' -i $file @@ -673,6 +691,11 @@ fi %files devel %endif +%files client-bash-completion +%{_datadir}/bash-completion/completions/openqa-cli +%files client-zsh-completion +%{_datadir}/zsh/site-functions/_openqa-cli + %files common %dir %{_datadir}/openqa %{_datadir}/openqa/lib diff --git a/docs/UsersGuide.asciidoc b/docs/UsersGuide.asciidoc index 50389e19a22..64b5fe23e1c 100644 --- a/docs/UsersGuide.asciidoc +++ b/docs/UsersGuide.asciidoc @@ -963,13 +963,9 @@ without needing to install openQA itself. Call `openqa-cli --help` for help. The sub-commands provide further help, e.g. `openqa-cli api --help` contains a lot of examples. -`openqa-cli` supports auto completion for `bash` and `zsh`. -If you use `bash` run or add the line below on your `.bashrc` profile. - -[source,sh] ----- -source openqa-cli-completion.bash ----- +`openqa-cli` supports auto completion for `bash` and `zsh` with openSUSE/SLE. +We distribute two packages `openQA-client-bash-completion` and +`openQA-client-zsh-completion` as part of openQA-client. This section focuses on particular API use-cases. Checkout the <> section for further information about