All of lore.kernel.org
 help / color / mirror / Atom feed
From: <Tim.Bird@sony.com>
To: daniel.sangorrin@toshiba.co.jp, fuego@lists.linuxfoundation.org
Subject: Re: [Fuego] [PATCH] bash-completion: add completion script for ftc
Date: Thu, 28 Feb 2019 00:21:33 +0000	[thread overview]
Message-ID: <ECADFF3FD767C149AD96A924E7EA6EAF8E0F938E@USCULXMSG01.am.sony.com> (raw)
In-Reply-To: <1551055620-35490-2-git-send-email-daniel.sangorrin@toshiba.co.jp>

This is very great stuff!!  This will be super handy.

One license issue, though.  See below.

> -----Original Message-----
> From: Daniel Sangorrin
> 
> Click [Tab] to have bash show you options or try to complete
> what you are writting
> 
> Signed-off-by: Daniel Sangorrin <daniel.sangorrin@toshiba.co.jp>
> ---
>  scripts/ftc_completion.sh | 176
> ++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 176 insertions(+)
>  create mode 100755 scripts/ftc_completion.sh
> 
> diff --git a/scripts/ftc_completion.sh b/scripts/ftc_completion.sh
> new file mode 100755
> index 0000000..2acb04e
> --- /dev/null
> +++ b/scripts/ftc_completion.sh
> @@ -0,0 +1,176 @@
> +# !/bin/bash
> +#
> +# Copyright (C) 2019 Toshiba corp.
> +# Author: Daniel Sangorrin <daniel.sangorrin@toshiba.co.jp>
> +#
> +# This library is free software; you can redistribute it and/or modify
> +# it under the terms of the GNU Lesser General Public License as
> +# published by the Free Software Foundation; either version 2 of the
> +# License, or (at your option) any later version.
I'd rather not accept this contribution under this license.
I'm not sure if any of the material below was derived from somewhere else
or not.  If so, that might pose a problem.  However, the default license
for Fuego is MIT.  I would be willing to allow this particular file, which is 
somewhat separate from the rest of Fuego, to be submitted at LGPL
version 2 only.  However, I really dislike the 'or any later version' clause
in this license header.  I don't want any part of Fuego to be susceptible
to conversion in to GPL or LGPL v3.

Please let me know if this is an issue.

> +#
> +# This library 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
> +# Lesser General Public License for more details.
> +#
> +# You should have received a copy of the GNU Lesser General Public
> +# License along with this library; if not, write to the Free Software
> +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
> +# USA.
> +#
> +# Bash completion script for Fuego's command line tool 'ftc'
> +#
> +# To enable the completions copy this file to
> +# /etc/bash_completion.d/ftc
> +# and make sure that your user's bashrc calls
> +# . /etc/bash_completion
> +
> +in_array() {
> +    local i
> +    for i in "${@:2}"; do
> +        [[ $1 = "$i" ]] && return
> +    done
> +}
> +
> +_ftc()
> +{
> +    local cur prev words cword
> +    local global_opts="-h --help -v -q -c -x --debug"
> +    declare -A percommand_opts=(
> +        ["add-jobs"]="-b -p -t -s --timeout --rebuild --reboot --precleanup --
> postcleanup"
> +        ["add-nodes"]="-f -b"
> +        ["add-view"]=""
> +        ["build-jobs"]=""
> +        ["config"]="-l"
> +        ["delete-var"]="-b"
> +        ["gen-report"]="--where --format --header_fields --fields --layout -o"
> +        ["help"]=""
> +        ["install-test"]="-u"
> +        ["list-boards"]="-q"
> +        ["list-jobs"]="-q"
> +        ["list-nodes"]="-q"
> +        ["list-plans"]="-q"
> +        ["list-requests"]="-q"
> +        ["list-runs"]="-q --where"
> +        ["list-specs"]="-q -t"
> +        ["list-tests"]="-q"
> +        ["package-run"]="-o -f"
> +        ["package-test"]="-o -f"
> +        ["put-request"]="-R -s"
> +        ["put-run"]=""
> +        ["put-test"]=""
> +        ["query-board"]="-b -n"
> +        ["release-resource"]="-b"
> +        ["reserve-resource"]="-f -b"
> +        ["rm-jobs"]="--remove-logs"
> +        ["rm-nodes"]=""
> +        ["rm-request"]=""
> +        ["run-request"]="--put-run"
> +        ["run-test"]="-b -t -s -p --timeout --rebuild --reboot --precleanup --
> postcleanup --dynamic-vars"
> +        ["set-var"]="-b"
> +        ["version"]=""
> +        ["wait-for"]="-i -t")
> +
> +    _init_completion || return
> +
> +    command="none"
> +    for word in "${COMP_WORDS[@]}"; do
> +        if in_array "$word" "${!percommand_opts[@]}"; then
> +            command=$word
> +            break
> +        fi
> +    done
> +
> +    # if no command yet, autocomplete with global options or commands
> +    if [ "$command" == "none" ]; then
> +        COMPREPLY=( $( compgen -W "$global_opts ${!percommand_opts[*]}"
> -- "$cur" ) )
> +        return 0
> +    fi
> +
> +    # otherwise, autocomplete with per-command options
> +    if [[ "$cur" == -* ]]; then
> +        COMPREPLY=( $( compgen -W "${percommand_opts[$command]}" --
> "$cur" ) )
> +        return 0
> +    fi
> +
> +    # if prev is an option, make sure it is allowed for the command
> +    if [[ "$prev" == -* ]]; then
> +        if [[ "${percommand_opts[$command]}" != *"$prev"* ]]; then
> +            return 0
> +        fi
> +    fi
> +
> +    # try to autocomplete each option
> +    case $prev in
> +        '-b')
> +            # FIXTHIS: support multiple boards separated by commas
> +            COMPREPLY=( $( compgen -W "$(ftc list-boards -q)" -- "$cur" ) )
> +            return 0
> +            ;;
> +        '-t')
> +            #FIXTHIS: distinguish test from timeout
> +            COMPREPLY=( $( compgen -W "$(ftc list-tests -q)" -- "$cur" ) )
> +            return 0
> +            ;;
> +        '-p')
> +            COMPREPLY=( $( compgen -W "$(ftc list-plans -q)" -- "$cur" ) )
> +            return 0
> +            ;;
> +        '--timeout')
> +            #FIXTHIS: try to complete
> +            return 0
> +            ;;
> +        '--rebuild' | '--reboot' | '--postcleanup' | '--precleanup')
> +            COMPREPLY=( $( compgen -W "true false" -- "$cur" ) )
> +            return 0
> +            ;;
> +        'put-run')
> +            COMPREPLY=( $( compgen -W "$(ftc list-runs -q)" -- "$cur" ) )
> +            return 0
> +            ;;
> +        'package-test')
> +            COMPREPLY=( $( compgen -W "$(ftc list-tests -q)" -- "$cur" ) )
> +            return 0
> +            ;;
> +        '--format')
> +            COMPREPLY=( $( compgen -W "txt html pdf excel csv rst" -- "$cur" ) )
> +            return 0
> +            ;;
> +        '-s')
> +            local i TEST=""
> +            for (( i=0; i < cword; i++ )); do
> +                if [[ "${words[i]}" == -t ]]; then
> +                TEST="${words[i + 1]}"
> +                fi
> +            done
> +            if [ -z "$TEST" ]; then
> +                return 0
> +            else
> +                COMPREPLY=( $( compgen -W "$(ftc list-specs -t $TEST -q)" -- "$cur"
> ) )
> +            fi
> +            return 0
> +            ;;
> +    esac
> +
> +    # deal with commands that use no opts
> +    if [[ "$command" == "build-jobs" || "$command" == "rm-jobs" ]]; then
> +            COMPREPLY=( $( compgen -W "$(ftc list-jobs -q)" -- "$cur" ) )
> +            return 0
> +    fi
> +
> +    if [[ "$command" == "rm-nodes" ]]; then
> +            COMPREPLY=( $( compgen -W "$(ftc list-nodes -q)" -- "$cur" ) )
> +            return 0
> +    fi
> +
> +    if [[ "$command" == "rm-request" ]]; then
> +            COMPREPLY=( $( compgen -W "$(ftc list-requests -q)" -- "$cur" ) )
> +            return 0
> +    fi
> +
> +    # if we have nothing, show available opts
> +    COMPREPLY=( $( compgen -W "${percommand_opts[$command]}" --
> "$cur" ) )
> +} &&
> +complete -F _ftc ftc
> +
> +# ex: ts=4 sw=4 et filetype=sh
> --
> 2.7.4

Other than the license issue, this looks good to me.  I'm not a bash completion
expert, although I did try to make a simple one for one of my other utilities.
I was hoping the '-q' options on the ftc commands would come in handy.  :-)

Let me know about the license issue.

For now, this is NOT applied.

Thanks,
 -- Tim


  reply	other threads:[~2019-02-28  0:21 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-25  0:46 [Fuego] Add bash-completion script for ftc Daniel Sangorrin
2019-02-25  0:47 ` [Fuego] [PATCH] bash-completion: add completion " Daniel Sangorrin
2019-02-28  0:21   ` Tim.Bird [this message]
2019-02-28  0:30   ` Tim.Bird
2019-02-28  7:47     ` daniel.sangorrin
2019-02-28 23:55       ` Tim.Bird
2019-03-01  0:41         ` daniel.sangorrin
  -- strict thread matches above, loose matches on Subject: below --
2019-02-25  0:42 Daniel Sangorrin
2019-02-28  0:14 ` Tim.Bird

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ECADFF3FD767C149AD96A924E7EA6EAF8E0F938E@USCULXMSG01.am.sony.com \
    --to=tim.bird@sony.com \
    --cc=daniel.sangorrin@toshiba.co.jp \
    --cc=fuego@lists.linuxfoundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.