From patchwork Sat Nov 4 15:00:25 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anthony Wong X-Patchwork-Id: 834191 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.ubuntu.com (client-ip=91.189.94.19; helo=huckleberry.canonical.com; envelope-from=fwts-devel-bounces@lists.ubuntu.com; receiver=) Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) by ozlabs.org (Postfix) with ESMTP id 3yThpR71rNz9sP1; Sun, 5 Nov 2017 02:00:47 +1100 (AEDT) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.86_2) (envelope-from ) id 1eAzwD-0006Xq-GQ; Sat, 04 Nov 2017 15:00:45 +0000 Received: from youngberry.canonical.com ([91.189.89.112]) by huckleberry.canonical.com with esmtps (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:128) (Exim 4.86_2) (envelope-from ) id 1eAzwA-0006X6-6y for fwts-devel@lists.ubuntu.com; Sat, 04 Nov 2017 15:00:42 +0000 Received: from mail-pg0-f69.google.com ([74.125.83.69]) by youngberry.canonical.com with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.76) (envelope-from ) id 1eAzw9-0001Bh-Rs for fwts-devel@lists.ubuntu.com; Sat, 04 Nov 2017 15:00:42 +0000 Received: by mail-pg0-f69.google.com with SMTP id m18so6946758pgd.13 for ; Sat, 04 Nov 2017 08:00:41 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id; bh=LSsm8+nBdiCpbsGcR56SoDIQAMTC0YZ7fpxue98l+/c=; b=qSr3H+WHMhrP2jitZ8VEQcWSaUml6RiHlQaq3p4+YYeN/TJMt4wG0nIVL95PDSrymT exlkjuTqK4CiUcAxzj7ZHin2cUwChuc9gpmRQ1qA5/mE/b6v3z7vyLqmJCUUt2MDpI5I SEa4Px1VR/OFV6C9alRir1cDQrcX8iHjQJjIt7W+k57pEKZuzPy/pHPBxN5HhLKuG4Td 0t8j5RPmHBcQCQQDl0IaBFx2dRW00begAbAVEh5tzdFV5kpOuC7HldDae1J3HRWGeVtZ keyDwkronz6ABblyGPVayockunjdZU4i4Qr6Yx0FDcOnAWL5kYUJjsMYdEtHR2Q9XW06 ussg== X-Gm-Message-State: AMCzsaU+MLgfrfVcl99skhAFOdQzxOQzaKEwUwz10A9UWNu7/rIs5gSG iNoPn2noXms2nA6I0bUWSOToJ8c3Q8omyK//jD29rkrp57gaMi5tVxO1N1w6Nn4uIrrPKd6RNfE u5yvD4kWygQDuY93jSPCmVZbtZK5fNKxho/PA1U/m X-Received: by 10.98.155.218 with SMTP id e87mr11076083pfk.96.1509807640138; Sat, 04 Nov 2017 08:00:40 -0700 (PDT) X-Google-Smtp-Source: ABhQp+R2b5iPUPp0X3FEBzdmxawY6t893FhXKp4qNnDTZSDT5sCd7ZH5KJV1Xrxu2PWMvP8znT8DPw== X-Received: by 10.98.155.218 with SMTP id e87mr11076067pfk.96.1509807639815; Sat, 04 Nov 2017 08:00:39 -0700 (PDT) Received: from localhost.localdomain ([159.89.202.31]) by smtp.gmail.com with ESMTPSA id p4sm13708270pga.58.2017.11.04.08.00.36 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 04 Nov 2017 08:00:38 -0700 (PDT) From: Anthony Wong To: fwts-devel@lists.ubuntu.com Subject: [PATCH] fwts: add bash command-line completion Date: Sat, 4 Nov 2017 23:00:25 +0800 Message-Id: <20171104150025.16379-1-anthony.wong@canonical.com> X-Mailer: git-send-email 2.14.1 X-BeenThere: fwts-devel@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Firmware Test Suite Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: fwts-devel-bounces@lists.ubuntu.com Sender: "fwts-devel" So that we can use tab to complete options and arguments, making fwts more enjoyable to use. Signed-off-by: Anthony Wong Acked-by: Colin Ian King Acked-by: Alex Hung --- Makefile.am | 2 +- configure.ac | 11 +++++ debian/fwts.install | 1 + scripts/bash-completion/Makefile.am | 2 + scripts/bash-completion/fwts | 86 +++++++++++++++++++++++++++++++++++++ 5 files changed, 101 insertions(+), 1 deletion(-) create mode 100644 scripts/bash-completion/Makefile.am create mode 100644 scripts/bash-completion/fwts diff --git a/Makefile.am b/Makefile.am index 278661c4..dcef6095 100644 --- a/Makefile.am +++ b/Makefile.am @@ -16,7 +16,7 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # -SUBDIRS = src data src/utilities +SUBDIRS = src data src/utilities scripts/bash-completion ACLOCAL_AMFLAGS = -I m4 diff --git a/configure.ac b/configure.ac index 2ef4f4f6..d7e0aee7 100644 --- a/configure.ac +++ b/configure.ac @@ -106,5 +106,16 @@ src/lib/src/Makefile src/utilities/Makefile data/Makefile + scripts/bash-completion/Makefile ]) + AC_ARG_WITH([bashcompletiondir], + AS_HELP_STRING([--with-bashcompletiondir=DIR], [Bash completions directory]), + [], + [AS_IF([`pkg-config --exists bash-completion`], [ + with_bashcompletiondir=`pkg-config --variable=completionsdir bash-completion` + ], [ + with_bashcompletiondir=${datadir}/bash-completion/completions + ]) + ]) + AC_SUBST([bashcompletiondir], [$with_bashcompletiondir]) AC_OUTPUT diff --git a/debian/fwts.install b/debian/fwts.install index ec150f3a..cb342d57 100644 --- a/debian/fwts.install +++ b/debian/fwts.install @@ -5,3 +5,4 @@ usr/bin/fwts usr/bin usr/share/man/man1/fwts.1 usr/share/man/man1 scripts/fwts-collect usr/bin usr/share/man/man1/fwts-collect.1 usr/share/man/man1 +usr/share/bash-completion/completions/fwts usr/share/bash-completion/completions diff --git a/scripts/bash-completion/Makefile.am b/scripts/bash-completion/Makefile.am new file mode 100644 index 00000000..a8b6ec8a --- /dev/null +++ b/scripts/bash-completion/Makefile.am @@ -0,0 +1,2 @@ +bashcompletiondir = @bashcompletiondir@ +dist_bashcompletion_DATA = fwts diff --git a/scripts/bash-completion/fwts b/scripts/bash-completion/fwts new file mode 100644 index 00000000..6cd0b25a --- /dev/null +++ b/scripts/bash-completion/fwts @@ -0,0 +1,86 @@ +#!/bin/bash +# +# FWTS tab completion for bash. +# +# Copyright (C) 2017 Canonical +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +_fwts() +{ + local cur prev + + cur=${COMP_WORDS[COMP_CWORD]} + prev=${COMP_WORDS[COMP_CWORD-1]} + + case $prev in + '--arch') + COMPREPLY=( $(compgen -W "x86 x86_32 x86_64 ia64 arm64 aarch64" -- $cur) ) + compopt -o nosort + return 0 + ;; + '--dumpfile'|'-k'|'--klog'|'-J'|'--json-data-file'|'--lspci'|'-o'|'--olog'|'--s3-resume-hook'|'-r'|'--results-output') + _filedir + return 0 + ;; + '-j'|'--json-data-path'|'-t'|'--table-path') + local IFS=$'\n' + compopt -o filenames + COMPREPLY=( $(compgen -d -- ${cur}) ) + return 0 + ;; + '--log-level') + COMPREPLY=( $(compgen -W "critical high medium low info all" -- $cur) ) + compopt -o nosort + return 0 + ;; + '--log-type') + COMPREPLY=( $(compgen -W "plaintext json xml" -- $cur) ) + return 0 + ;; + '--pm-method') + COMPREPLY=( $(compgen -W "logind pm-utils sysfs" -- $cur) ) + return 0 + ;; + '--log-filter'|'--log-format'|'-w'|'--log-width'|'-R'|'-rsdp'|\ + '--s3-delay-delta'|'--s3-device-check-delay'|'--s3-max-delay'|'--s3-min-delay'|'--s3-multiple'|\ + '--s3-quirks'|'--s3-resume-time'|'--s3-sleep-delay'|'--s3-suspend-time'|'--s3power-sleep-delay'|\ + '--s4-delay-delta'|'--s4-device-check-delay'|'--s4-max-delay'|'--s4-min-delay'|'--s4-multiple'|'--s4-quirks'|'--s4-sleep-delay'|\ + '-s'|'--skip-test'|'--uefi-get-var-multiple'|'--uefi-query-var-multiple'|'--uefi-set-var-multiple') + # argument required but no completions available + return 0 + ;; + '-h'|'--help'|'-v'|'--version'|'-d'|'--dump'|'-s'|'--show-tests'|'--show-tests-full'|'--show-tests-categories'|'--log-fields') + # all other arguments are noop with these + return 0 + ;; + esac + + local all_tests=`fwts --show-tests | sed '/.*:/d;/^$/d' | awk '{ print $1 }'` + local all_long_options=$( _parse_help "$1" --help ) + + if [ -z "$cur" ]; then + COMPREPLY=( $( compgen -W "${all_tests}" -- "$cur" ) ) + else + COMPREPLY=( $( compgen -W "${all_tests} ${all_long_options}" -- "$cur" ) ) + + fi + + return 0 +} + + +# load the completion +complete -F _fwts fwts