From 44b1e103b4d3a24aee89587ef302891e9f9c3807 Mon Sep 17 00:00:00 2001 From: EuAndreh Date: Fri, 17 Feb 2023 15:07:30 -0300 Subject: bin/: Use explicit "--" separator for assert-arg usages In order to prevent legitimate cases to fail as errors, such as: NUM='-10' eval "$(assert-arg "$NUM" '-n NUM')" To prevent assert-arg(1) from treating "-10" as the options "-1 and -0, they need to be put after the "--" separator. This way, all usages of assert-arg(1) that had its first argument as a variable were adapted, and the usage and examples of assert-arg itself were updated to encourage this best practice. --- bin/assert-arg | 4 ++-- bin/clamp | 6 +++--- bin/color | 4 ++-- bin/email | 4 ++-- bin/forever | 2 +- bin/grun | 4 ++-- bin/lines | 2 +- bin/menu | 2 +- bin/msg | 8 ++++---- bin/n-times | 2 +- bin/ootb | 2 +- bin/player | 2 +- bin/playlist | 2 +- bin/pre | 2 +- bin/prompt | 2 +- bin/rfc | 2 +- bin/vcs | 2 +- bin/vm | 6 +++--- bin/volume | 2 +- bin/with-email | 2 +- bin/without-env | 4 ++-- bin/wms | 2 +- 22 files changed, 34 insertions(+), 34 deletions(-) (limited to 'bin') diff --git a/bin/assert-arg b/bin/assert-arg index d7bc8f4d..3c8990ab 100755 --- a/bin/assert-arg +++ b/bin/assert-arg @@ -4,7 +4,7 @@ set -eu usage() { cat <<-'EOF' Usage: - assert-arg STRING MESSAGE + assert-arg -- STRING MESSAGE assert-arg -h EOF } @@ -23,7 +23,7 @@ help() { Assert that $1 contains an argument, named FILENAME: - $ eval "$(assert-arg "${1:-}" 'FILENAME')" + $ eval "$(assert-arg -- "${1:-}" 'FILENAME')" EOF } diff --git a/bin/clamp b/bin/clamp index a673f725..fab69672 100755 --- a/bin/clamp +++ b/bin/clamp @@ -73,9 +73,9 @@ NUMBER="${1:-}" MIN="${2:-}" MAX="${3:-}" -eval "$(assert-arg "$NUMBER" 'NUMBER')" -eval "$(assert-arg "$MIN" 'MIN')" -eval "$(assert-arg "$MAX" 'MAX')" +eval "$(assert-arg -- "$NUMBER" 'NUMBER')" +eval "$(assert-arg -- "$MIN" 'MIN')" +eval "$(assert-arg -- "$MAX" 'MAX')" if [ "$MIN" -gt "$MAX" ]; then diff --git a/bin/color b/bin/color index dc610e99..240da874 100755 --- a/bin/color +++ b/bin/color @@ -208,8 +208,8 @@ shift $((OPTIND - 1)) TEXT="${1:-}" -eval "$(assert-arg "$COLOR_FN" '-c COLOR')" -eval "$(assert-arg "$TEXT" 'TEXT')" +eval "$(assert-arg -- "$COLOR_FN" '-c COLOR')" +eval "$(assert-arg -- "$TEXT" 'TEXT')" "$COLOR_FN" "$TEXT" diff --git a/bin/email b/bin/email index d4277703..3e336d2a 100755 --- a/bin/email +++ b/bin/email @@ -72,8 +72,8 @@ shift $((OPTIND - 1)) ADDRESS="${1:-}" -eval "$(assert-arg "${SUBJECT:-}" '-s SUBJECT')" -eval "$(assert-arg "$ADDRESS" 'ADDRESS')" +eval "$(assert-arg -- "${SUBJECT:-}" '-s SUBJECT')" +eval "$(assert-arg -- "$ADDRESS" 'ADDRESS')" { cat <<-EOF diff --git a/bin/forever b/bin/forever index d4410e59..1ecc2a88 100755 --- a/bin/forever +++ b/bin/forever @@ -58,7 +58,7 @@ while getopts 'h' flag; do done shift $((OPTIND - 1)) -eval "$(assert-arg "${1:-}" 'COMMAND')" +eval "$(assert-arg -- "${1:-}" 'COMMAND')" while true; do diff --git a/bin/grun b/bin/grun index 74d88192..e9cfebea 100755 --- a/bin/grun +++ b/bin/grun @@ -72,7 +72,7 @@ done shift $((OPTIND - 1)) FILENAME="${1:-}" -eval "$(assert-arg "$FILENAME" 'FILENAME')" +eval "$(assert-arg -- "$FILENAME" 'FILENAME')" shift if [ "${1:-}" != '--' ]; then @@ -82,7 +82,7 @@ if [ "${1:-}" != '--' ]; then fi shift -eval "$(assert-arg "${1:-}" 'COMMAND')" +eval "$(assert-arg -- "${1:-}" 'COMMAND')" if [ ! -e "$FILENAME" ]; then diff --git a/bin/lines b/bin/lines index 2f0bf468..6cda6f08 100755 --- a/bin/lines +++ b/bin/lines @@ -76,6 +76,6 @@ else END=$(($2 - START + 1)) fi -eval "$(assert-arg "$START" 'START')" +eval "$(assert-arg -- "$START" 'START')" tail -n +"$START" | head -n "$END" diff --git a/bin/menu b/bin/menu index 3fd30954..0851cab6 100755 --- a/bin/menu +++ b/bin/menu @@ -72,7 +72,7 @@ done shift $((OPTIND - 1)) ACTION="${1:-}" -eval "$(assert-arg "$ACTION" 'ACTION')" +eval "$(assert-arg -- "$ACTION" 'ACTION')" DATA() { diff --git a/bin/msg b/bin/msg index 0f9cced0..84d25a75 100755 --- a/bin/msg +++ b/bin/msg @@ -124,22 +124,22 @@ fi MESSAGE="${1:-}" if [ "$XMPP" = true ]; then - eval "$(assert-arg "$MESSAGE" '-X MESSAGE')" + eval "$(assert-arg -- "$MESSAGE" '-X MESSAGE')" xmpp -m "$MESSAGE" eu@euandre.org & fi if [ "$SOUND" = true ]; then sound & fi if [ "$SPEAK" = true ]; then - eval "$(assert-arg "$MESSAGE" '-S MESSAGE')" + eval "$(assert-arg -- "$MESSAGE" '-S MESSAGE')" echo "$MESSAGE" | speak -v pt-BR & fi if [ "$MAIL" = true ]; then - eval "$(assert-arg "$MESSAGE" '-m MESSAGE')" + eval "$(assert-arg -- "$MESSAGE" '-m MESSAGE')" echo " " | email -s "$MESSAGE" eu@euandre.org & fi if [ "$DESKTOP" = true ]; then - eval "$(assert-arg "$MESSAGE" '-D MESSAGE')" + eval "$(assert-arg -- "$MESSAGE" '-D MESSAGE')" if [ "$OK" = true ]; then notify-send -t 5000 "$MESSAGE" & else diff --git a/bin/n-times b/bin/n-times index 4fa8b96f..c8d10d83 100755 --- a/bin/n-times +++ b/bin/n-times @@ -61,7 +61,7 @@ shift $((OPTIND - 1)) COUNT="${1:-}" shift -eval "$(assert-arg "$COUNT" 'COUNT')" +eval "$(assert-arg -- "$COUNT" 'COUNT')" while true; do diff --git a/bin/ootb b/bin/ootb index 3aa58dbf..2b984547 100755 --- a/bin/ootb +++ b/bin/ootb @@ -93,7 +93,7 @@ shift $((OPTIND - 1)) BUILD_DIRECTORY="${1:-}" -eval "$(assert-arg "$BUILD_DIRECTORY" 'BUILD_DIRECTORY')" +eval "$(assert-arg -- "$BUILD_DIRECTORY" 'BUILD_DIRECTORY')" mkdir -p "$BUILD_DIRECTORY" diff --git a/bin/player b/bin/player index b6e66d79..cea0e215 100755 --- a/bin/player +++ b/bin/player @@ -73,7 +73,7 @@ done shift $((OPTIND - 1)) ACTION="${1:-}" -eval "$(assert-arg "$ACTION" 'ACTION')" +eval "$(assert-arg -- "$ACTION" 'ACTION')" diff --git a/bin/playlist b/bin/playlist index bd01d232..8b9271fa 100755 --- a/bin/playlist +++ b/bin/playlist @@ -67,7 +67,7 @@ done shift $((OPTIND - 1)) ACTION="${1:-}" -eval "$(assert-arg "$ACTION" 'ACTION')" +eval "$(assert-arg -- "$ACTION" 'ACTION')" F="$XDG_DATA_HOME"/euandreh/playlist.txt diff --git a/bin/pre b/bin/pre index 2b32f8f9..f5883102 100755 --- a/bin/pre +++ b/bin/pre @@ -67,7 +67,7 @@ done shift $((OPTIND - 1)) PREFIX="${1:-}" -eval "$(assert-arg "$PREFIX" 'PREFIX')" +eval "$(assert-arg -- "$PREFIX" 'PREFIX')" while read -r line; do if [ -z "$COLOR" ]; then diff --git a/bin/prompt b/bin/prompt index 247c81a1..382588dc 100755 --- a/bin/prompt +++ b/bin/prompt @@ -64,7 +64,7 @@ done shift $((OPTIND - 1)) STRING="${1:-}" -eval "$(assert-arg "$STRING" 'STRING')" +eval "$(assert-arg -- "$STRING" 'STRING')" printf '%s' "$STRING" printf ' [Y/n]: ' diff --git a/bin/rfc b/bin/rfc index 9c71ebc4..0860f451 100755 --- a/bin/rfc +++ b/bin/rfc @@ -133,7 +133,7 @@ if [ "${UPDATE:-}" = true ]; then exit fi -eval "$(assert-arg "$RFC_NUMBER" 'RFC_NUMBER')" +eval "$(assert-arg -- "$RFC_NUMBER" 'RFC_NUMBER')" if [ ! -e "$F" ]; then printf 'Given RFC_NUMBER "%s" does not exist at:\n%s\n' \ diff --git a/bin/vcs b/bin/vcs index 33bae3c2..cbb34aa7 100755 --- a/bin/vcs +++ b/bin/vcs @@ -232,7 +232,7 @@ done shift $((OPTIND - 1)) ACTION="${1:-}" -eval "$(assert-arg "$ACTION" 'ACTION')" +eval "$(assert-arg -- "$ACTION" 'ACTION')" shift if [ "${1:-}" = '--' ]; then diff --git a/bin/vm b/bin/vm index bfd182aa..2296f726 100755 --- a/bin/vm +++ b/bin/vm @@ -214,7 +214,7 @@ write_ssh_config ACTION="${1:-}" OS="${2:-}" -eval "$(assert-arg "$ACTION" 'ACTION')" +eval "$(assert-arg -- "$ACTION" 'ACTION')" shift @@ -247,7 +247,7 @@ case "$ACTION" in done ;; up) - eval "$(assert-arg "$OS" 'OS')" + eval "$(assert-arg -- "$OS" 'OS')" shift if [ "${1:-}" = '--' ]; then shift @@ -301,7 +301,7 @@ case "$ACTION" in write_ssh_config ;; down) - eval "$(assert-arg "$OS" 'OS')" + eval "$(assert-arg -- "$OS" 'OS')" shift if [ "${1:-}" = '--' ]; then shift diff --git a/bin/volume b/bin/volume index 991fbc7d..9056760f 100755 --- a/bin/volume +++ b/bin/volume @@ -74,7 +74,7 @@ done shift $((OPTIND - 1)) ACTION="${1:-}" -eval "$(assert-arg "$ACTION" 'ACTION')" +eval "$(assert-arg -- "$ACTION" 'ACTION')" rotate() { diff --git a/bin/with-email b/bin/with-email index 7df101ac..bd3ef96a 100755 --- a/bin/with-email +++ b/bin/with-email @@ -69,7 +69,7 @@ while getopts 's:h' flag; do done shift $((OPTIND - 1)) -eval "$(assert-arg "${1:-}" 'COMMAND...')" +eval "$(assert-arg -- "${1:-}" 'COMMAND...')" now() { date '+%Y-%m-%dT%H:%M:%S%Z' diff --git a/bin/without-env b/bin/without-env index fd9d1e8c..57c2d2e2 100755 --- a/bin/without-env +++ b/bin/without-env @@ -57,8 +57,8 @@ while getopts 'h' flag; do done shift $((OPTIND - 1)) -eval "$(assert-arg "${1:-}" 'ENVVAR')" -eval "$(assert-arg "${2:-}" 'PATH')" +eval "$(assert-arg -- "${1:-}" 'ENVVAR')" +eval "$(assert-arg -- "${2:-}" 'PATH')" eval "export $1=\"\$(echo \"\$$1\" | sed \"s|\$2:||g\")\"" shift # drop $1 diff --git a/bin/wms b/bin/wms index 03b5b055..a2df5bfa 100755 --- a/bin/wms +++ b/bin/wms @@ -67,7 +67,7 @@ done shift $((OPTIND - 1)) ACTION="${1:-}" -eval "$(assert-arg "$ACTION" 'ACTION')" +eval "$(assert-arg -- "$ACTION" 'ACTION')" copy_and_notify() { -- cgit v1.3