From: Bastian Krause <bst@pengutronix.de>
To: ptxdist@pengutronix.de
Cc: Bastian Krause <bst@pengutronix.de>
Subject: [ptxdist] [PATCH v3 1/6] ptxd_lib_template: add ptxd_template_read_options
Date: Wed, 17 Jun 2020 16:31:20 +0200 [thread overview]
Message-ID: <20200617143125.23999-2-bst@pengutronix.de> (raw)
In-Reply-To: <20200617143125.23999-1-bst@pengutronix.de>
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>
---
Introduced in v3. Used to ask user about HSM type in a later commit.
---
scripts/lib/ptxd_lib_template.sh | 26 ++++++++++++++++++++++++++
1 file changed, 26 insertions(+)
diff --git a/scripts/lib/ptxd_lib_template.sh b/scripts/lib/ptxd_lib_template.sh
index f39e6e033..6b405763b 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
--
2.27.0
_______________________________________________
ptxdist mailing list
ptxdist@pengutronix.de
To unsubscribe, send a mail with subject "unsubscribe" to ptxdist-request@pengutronix.de
next prev parent reply other threads:[~2020-06-17 14:31 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 ` Bastian Krause [this message]
2020-06-19 6:24 ` [ptxdist] [PATCH v3 1/6] ptxd_lib_template: add ptxd_template_read_options Michael Olbrich
2020-06-19 8:13 ` Bastian Krause
2020-06-19 22:04 ` [ptxdist] [APPLIED] " Michael Olbrich
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=20200617143125.23999-2-bst@pengutronix.de \
--to=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