diff options
author | Bernd Weimer <bernd.weimer@pelagicore.com> | 2018-01-18 11:27:47 +0100 |
---|---|---|
committer | Dominik Holland <dominik.holland@pelagicore.com> | 2018-01-23 09:43:04 +0000 |
commit | 2c5aa14677e3038ee46bf727122f090497e777ba (patch) | |
tree | 43ac46592030ebe250a7bb08c2289b1a08399913 | |
parent | b956d8ff205eaaf2e8f83446e2023fd491562669 (diff) | |
download | qtapplicationmanager-2c5aa14677e3038ee46bf727122f090497e777ba.tar.gz |
Add bash command completion file
It provides command completion for appman-controller and appman-packager.
Change-Id: Ic8853c55c8a484fa7fb498f822727f167ad4b2e9
Reviewed-by: Dominik Holland <dominik.holland@pelagicore.com>
-rw-r--r-- | src/tools/controller/controller.cpp | 2 | ||||
-rw-r--r-- | src/tools/packager/packager.cpp | 2 | ||||
-rw-r--r-- | util/bash/README | 26 | ||||
-rw-r--r-- | util/bash/appman-prompt | 105 |
4 files changed, 135 insertions, 0 deletions
diff --git a/src/tools/controller/controller.cpp b/src/tools/controller/controller.cpp index 897cde31..fa0004b8 100644 --- a/src/tools/controller/controller.cpp +++ b/src/tools/controller/controller.cpp @@ -142,6 +142,7 @@ enum Command { ShowInstallationLocation }; +// REMEMBER to update the completion file util/bash/appman-prompt, if you apply changes below! static struct { Command command; const char *name; @@ -254,6 +255,7 @@ int main(int argc, char *argv[]) } clp.setOptionsAfterPositionalArgumentsMode(QCommandLineParser::ParseAsOptions); + // REMEMBER to update the completion file util/bash/appman-prompt, if you apply changes below! try { switch (command(clp)) { default: diff --git a/src/tools/packager/packager.cpp b/src/tools/packager/packager.cpp index f595b595..3de8bdd0 100644 --- a/src/tools/packager/packager.cpp +++ b/src/tools/packager/packager.cpp @@ -48,6 +48,7 @@ enum Command { StoreVerifyPackage, }; +// REMEMBER to update the completion file util/bash/appman-prompt, if you apply changes below! static struct { Command command; const char *name; @@ -125,6 +126,7 @@ int main(int argc, char *argv[]) PackagingJob *p = nullptr; + // REMEMBER to update the completion file util/bash/appman-prompt, if you apply changes below! switch (command(clp)) { default: case NoCommand: diff --git a/util/bash/README b/util/bash/README new file mode 100644 index 00000000..1702f83b --- /dev/null +++ b/util/bash/README @@ -0,0 +1,26 @@ +Abstract +======== +The appman-prompt script provides command completion inside a bash shell for +the appman-controller and appman-packager commands. + +Installation +============ +As a prerequisite the bash-completion package needs not be installed. The +appman-prompt script itself can be installed in one of the following ways: + +1. Copy appman-prompt into the /etc/bash_completion.d folder + (or whatever "pkg-config --variable=compatdir bash-completion" yields) + +2. Copy the contents of appman-prompt into the ~/.bash_completion file + +Afterwards completion will be available in new shells. + +Notes +===== +(Sub-)Command options are currently not supported, only the general ones (help +and version). + +Users of the zsh shell might want to run the following commands to get going: +autoload bashcompinit +bashcompinit +source /etc/bash_completion.d/appman-prompt diff --git a/util/bash/appman-prompt b/util/bash/appman-prompt new file mode 100644 index 00000000..554bef90 --- /dev/null +++ b/util/bash/appman-prompt @@ -0,0 +1,105 @@ +############################################################################# +## +## Copyright (C) 2018 Pelagicore AG +## Contact: https://www.qt.io/licensing/ +## +## This file is part of the Pelagicore Application Manager. +## +## $QT_BEGIN_LICENSE:GPL-EXCEPT-QTAS$ +## Commercial License Usage +## Licensees holding valid commercial Qt Automotive Suite licenses may use +## this file in accordance with the commercial license agreement provided +## with the Software or, alternatively, in accordance with the terms +## contained in a written agreement between you and The Qt Company. For +## licensing terms and conditions see https://www.qt.io/terms-conditions. +## For further information use the contact form at https://www.qt.io/contact-us. +## +## GNU General Public License Usage +## Alternatively, this file may be used under the terms of the GNU +## General Public License version 3 as published by the Free Software +## Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +## included in the packaging of this file. Please review the following +## information to ensure the GNU General Public License requirements will +## be met: https://www.gnu.org/licenses/gpl-3.0.html. +## +## $QT_END_LICENSE$ +## +############################################################################# + +_appman-controller() +{ + local cur commands opts pos args + COMPREPLY=() + cur="${COMP_WORDS[COMP_CWORD]}" + commands="start-application debug-application stop-application stop-all-applications list-applications show-application install-package remove-package list-installation-locations show-installation-location" + opts="-h -v --help --version" + + if [ ${COMP_CWORD} -eq 1 ] && [[ ${cur} == -* ]] ; then + COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) + else + pos=0 + args=() + for i in "${COMP_WORDS[@]:1:${COMP_CWORD}}" ; do + [[ ${i} != -* ]] && ((++pos)) && args+=(${i}) + done + + if [ ${pos} -eq 1 ]; then + COMPREPLY=( $(compgen -W "${commands}" -- ${cur}) ) + elif [ ${pos} -eq 2 ]; then + case "${args[0]}" in + start-application|debug-application|stop-application|show-application|remove-package) + eval cmd="${COMP_WORDS[0]}" + apps="$(${cmd} list-applications 2> /dev/null)" + COMPREPLY=( $(compgen -W "${apps}" -- ${cur}) ) + ;; + install-package) + COMPREPLY=( $( compgen -f -- ${cur}) ) + ;; + show-installation-location) + eval cmd="${COMP_WORDS[0]}" + apps="$(${cmd} list-applications 2> /dev/null)" + COMPREPLY=( $(compgen -W "${apps}" -- ${cur}) ) + ;; + esac + fi + fi +} +complete -o filenames -F _appman-controller appman-controller + +_appman-packager() +{ + local cur commands opts pos args + COMPREPLY=() + cur="${COMP_WORDS[COMP_CWORD]}" + commands="create-package dev-sign-package dev-verify-package store-sign-package store-verify-package" + opts="-h -v --help --version" + + if [ ${COMP_CWORD} -eq 1 ] && [[ ${cur} == -* ]] ; then + COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) + else + pos=0 + args=() + for i in "${COMP_WORDS[@]:1:${COMP_CWORD}}" ; do + [[ ${i} != -* ]] && ((++pos)) && args+=(${i}) + done + + if [ ${pos} -eq 1 ]; then + COMPREPLY=( $(compgen -W "${commands}" -- ${cur}) ) + else + file=0 + case "${args[0]}" in + create-package) + [ ${pos} -eq 3 ] && file=1 + ;; + dev-sign-package|store-sign-package) + [ ${pos} -lt 5 ] && file=1 + ;; + dev-verify-package|store-verify-package) + file=1 + ;; + esac + [ ${file} -eq 1 ] && COMPREPLY=( $( compgen -f -- ${cur}) ) + fi + fi +} +complete -o filenames -F _appman-packager appman-packager |