mailarchive of the ptxdist mailing list
 help / color / mirror / Atom feed
From: Michael Olbrich <mol@pengutronix.de>
To: ptxdist@pengutronix.de
Cc: Bastian Krause <bst@pengutronix.de>
Subject: Re: [ptxdist] [APPLIED] ptxd_lib_template: add ptxd_template_read_options
Date: Sat, 20 Jun 2020 00:04:06 +0200	[thread overview]
Message-ID: <E1jmP7G-0002Os-4E@dude02.lab.pengutronix.de> (raw)
In-Reply-To: <20200617143125.23999-2-bst@pengutronix.de>

Thanks, applied as bf1a401a968193cf8fd8ebc4a6f8c899c2c3bae3.

Michael

[sent from post-receive hook]

On Sat, 20 Jun 2020 00:04:06 +0200, Bastian Krause <bst@pengutronix.de> wrote:
> Read a variable from user input, limited to a set of options.
> 
> Example:
> 
>   $ ptxd_template_read_options "select your option" TYPE "option A" "option B" "option C"
>   ptxdist: select option by number:
>   ptxdist: [1] option A
>   ptxdist: [2] option B
>   ptxdist: [3] option C
>   ptxdist: select your option................: 2
>   $ echo $TYPE
>   option B
> 
> The user can select 1, 2 or 3. Other input is not accepted.
> 
> Signed-off-by: Bastian Krause <bst@pengutronix.de>
> Message-Id: <20200617143125.23999-2-bst@pengutronix.de>
> [mol: fix indention]
> Signed-off-by: Michael Olbrich <m.olbrich@pengutronix.de>
> 
> diff --git a/scripts/lib/ptxd_lib_template.sh b/scripts/lib/ptxd_lib_template.sh
> index 3d47cd85a4c4..9cace6c14a0b 100644
> --- a/scripts/lib/ptxd_lib_template.sh
> +++ b/scripts/lib/ptxd_lib_template.sh
> @@ -30,6 +30,32 @@ ptxd_template_read() {
>      export "${2}"
>  }
>  export -f ptxd_template_read
> +#
> +# Read a variable from user input, limited to an array of options
> +#
> +# $1 prompt prefix
> +# $2 variable name
> +# $3..$n options
> +#
> +ptxd_template_read_options() {
> +    local -a options=("${@:3}")
> +    local i=1
> +    echo "${PTXDIST_LOG_PROMPT}select option by number:"
> +    for option in "${options[@]}"; do
> +	echo "${PTXDIST_LOG_PROMPT}[${i}] ${option}"
> +	((i++))
> +    done
> +    while : ; do
> +	ptxd_template_read "${1}" chosen
> +	[ -n "${chosen}" ] && [ "${chosen}" -gt 0 ] &&
> +	[ "${chosen}" -le "${#options[@]}" ] &&
> +	break
> +
> +	echo "${PTXDIST_LOG_PROMPT}invalid option"
> +    done
> +    export "${2}=${options[$chosen-1]}"
> +}
> +export -f ptxd_template_read_options
>  
>  ptxd_template_read_name() {
>      ptxd_template_read "enter package name" package_name

_______________________________________________
ptxdist mailing list
ptxdist@pengutronix.de
To unsubscribe, send a mail with subject "unsubscribe" to ptxdist-request@pengutronix.de

  parent reply	other threads:[~2020-06-19 22:04 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-17 14:31 [ptxdist] [PATCH v3 0/6] Add code-signing-provider template, add code signing docs Bastian Krause
2020-06-17 14:31 ` [ptxdist] [PATCH v3 1/6] ptxd_lib_template: add ptxd_template_read_options Bastian Krause
2020-06-19  6:24   ` Michael Olbrich
2020-06-19  8:13     ` Bastian Krause
2020-06-19 22:04   ` Michael Olbrich [this message]
2020-06-17 14:31 ` [ptxdist] [PATCH v3 2/6] package templates: add code-signing-provider template Bastian Krause
2020-06-18 11:40   ` Roland Hieber
2020-06-18 11:50     ` Bastian Krause
2020-06-19  6:12       ` Michael Olbrich
2020-06-19  6:28   ` Michael Olbrich
2020-06-19  7:52     ` Bastian Krause
2020-06-19 22:04   ` [ptxdist] [APPLIED] " Michael Olbrich
2020-09-24 10:04   ` [ptxdist] [PATCH v3 2/6] " Ladislav Michl
2020-09-24 11:05     ` Bastian Krause
2020-09-24 11:15       ` Ladislav Michl
2020-09-24 12:23         ` Bastian Krause
2020-06-17 14:31 ` [ptxdist] [PATCH v3 3/6] doc: dev_manual: split up into multiple files Bastian Krause
2020-06-19 22:04   ` [ptxdist] [APPLIED] " Michael Olbrich
2020-06-17 14:31 ` [ptxdist] [PATCH v3 4/6] doc: move code signing docs from scripts/ into doc/ Bastian Krause
2020-06-19 22:04   ` [ptxdist] [APPLIED] " Michael Olbrich
2020-06-17 14:31 ` [ptxdist] [PATCH v3 5/6] doc: dev_code_signing: rework and extend code signing section Bastian Krause
2020-06-19 22:04   ` [ptxdist] [APPLIED] " Michael Olbrich
2020-06-17 14:31 ` [ptxdist] [PATCH v3 6/6] doc: introduce ref_code_signing_helpers Bastian Krause
2020-06-19 22:04   ` [ptxdist] [APPLIED] " Michael Olbrich

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=E1jmP7G-0002Os-4E@dude02.lab.pengutronix.de \
    --to=mol@pengutronix.de \
    --cc=bst@pengutronix.de \
    --cc=ptxdist@pengutronix.de \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox