From a0188f38d8a9702dd3d7119375173d063a5f28bc Mon Sep 17 00:00:00 2001 From: EuAndreh Date: Sat, 13 Aug 2022 10:58:10 -0300 Subject: bin/: Replace usage of assert_arg with assert-arg --- bin/email | 15 ++------------- bin/grun | 12 ++---------- bin/msg | 16 ++++------------ bin/pre | 10 +--------- bin/prompt | 10 +--------- bin/rfc | 10 +--------- bin/without-env | 13 +++---------- 7 files changed, 14 insertions(+), 72 deletions(-) (limited to 'bin') diff --git a/bin/email b/bin/email index 3c72086..c16ed62 100755 --- a/bin/email +++ b/bin/email @@ -64,19 +64,8 @@ while getopts 's:h' flag; do done shift $((OPTIND - 1)) -assert_arg() { - if [ -z "$1" ]; then - { - printf 'Missing %s.\n' "$2" - printf '\n' - usage - } >&2 - exit 2 - fi -} - -assert_arg "${SUBJECT:-}" '-s SUBJECT' -assert_arg "${1:-}" 'ADDRESS' +eval "$(assert-arg "${SUBJECT:-}" '-s SUBJECT')" +eval "$(assert-arg "${1:-}" 'ADDRESS')" printf 'Subject: %s\n\n%s' \ "$(echo "$SUBJECT" | tr -d '\n')" \ diff --git a/bin/grun b/bin/grun index cfd6b52..982420a 100755 --- a/bin/grun +++ b/bin/grun @@ -71,16 +71,8 @@ while getopts 'rh' flag; do done shift $((OPTIND - 1)) -assert_arg() { - if [ -z "$1" ]; then - printf 'Missing %s\n\n' "$2" >&2 - usage >&2 - exit 2 - fi -} - FILENAME="${1:-}" -assert_arg "$FILENAME" 'FILENAME' +eval "$(assert-arg "$FILENAME" 'FILENAME')" shift if [ "${1:-}" != '--' ]; then @@ -90,7 +82,7 @@ if [ "${1:-}" != '--' ]; then fi shift -assert_arg "${1:-}" 'COMMAND' +eval "$(assert-arg "${1:-}" 'COMMAND')" if [ ! -e "$FILENAME" ]; then diff --git a/bin/msg b/bin/msg index ad0b608..f685ffb 100755 --- a/bin/msg +++ b/bin/msg @@ -124,31 +124,23 @@ fi MESSAGE="${1:-}" -assert_arg() { - if [ -z "$1" ]; then - printf 'Missing %s.\n\n' "$2" >&2 - usage >&2 - exit 2 - fi -} - if [ "$XMPP" = true ]; then - assert_arg "$MESSAGE" '-X MESSAGE' + eval "$(assert-arg "$MESSAGE" '-X MESSAGE')" xmpp -m "$MESSAGE" eu@euandreh.xyz & fi if [ "$SOUND" = true ]; then sound & fi if [ "$SPEAK" = true ]; then - assert_arg "$MESSAGE" '-S MESSAGE' + eval "$(assert-arg "$MESSAGE" '-S MESSAGE')" echo "$MESSAGE" | speak -v pt-BR & fi if [ "$MAIL" = true ]; then - assert_arg "$MESSAGE" '-m MESSAGE' + eval "$(assert-arg "$MESSAGE" '-m MESSAGE')" echo " " | email -s "$MESSAGE" eu@euandre.org & fi if [ "$DESKTOP" = true ]; then - 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/pre b/bin/pre index 233ac1a..79c212f 100755 --- a/bin/pre +++ b/bin/pre @@ -52,16 +52,8 @@ while getopts 'c:h' flag; do done shift $((OPTIND - 1)) -assert_arg() { - if [ -z "$1" ]; then - printf 'Missing %s\n\n' "$2" >&2 - usage >&2 - exit 2 - fi -} - PREFIX="${1:-}" -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 a191238..68dff61 100755 --- a/bin/prompt +++ b/bin/prompt @@ -23,14 +23,6 @@ help() { EOF } -assert_arg() { - if [ -z "$1" ]; then - printf 'Missing %s.\n\n' "$2" >&2 - usage >&2 - exit 2 - fi -} - for flag in "$@"; do case "$flag" in @@ -63,7 +55,7 @@ done shift $((OPTIND - 1)) STRING="${1:-}" -assert_arg "$STRING" 'STRING' +eval "$(assert-arg "$STRING" 'STRING')" printf '%s' "$STRING" printf ' [Y/n]: ' diff --git a/bin/rfc b/bin/rfc index e0da425..bd8fb67 100755 --- a/bin/rfc +++ b/bin/rfc @@ -86,14 +86,6 @@ check_local_db() { fi } -assert_arg() { - if [ -z "$1" ]; then - printf 'Missing %s.\n\n' "$2" >&2 - usage >&2 - exit 2 - fi -} - for flag in "$@"; do case "$flag" in @@ -141,7 +133,7 @@ if [ "${UPDATE:-}" = true ]; then exit fi -assert_arg "$RFC_NUMBER" +eval "$(assert-arg "$RFC_NUMBER")" if [ ! -e "$F" ]; then printf 'Given RFC_NUMBER "%s" does not exist at:\n%s\n' \ diff --git a/bin/without-env b/bin/without-env index 45c41ca..4f8fb14 100755 --- a/bin/without-env +++ b/bin/without-env @@ -57,16 +57,9 @@ while getopts 'h' flag; do done shift $((OPTIND - 1)) -assert_arg() { - if [ -z "$1" ]; then - printf 'Missing %s\n' "$2" >&2 - exit 2 - fi -} - -assert_arg "${1:-}" 'ENVVAR' -assert_arg "${2:-}" 'PATH' -assert_arg "${3:-}" '--' +eval "$(assert-arg "${1:-}" 'ENVVAR')" +eval "$(assert-arg "${2:-}" 'PATH')" +eval "$(assert-arg "${3:-}" '--')" eval "export $1=\"\$(echo \"\$$1\" | sed \"s|\$2:||g\")\"" shift # drop $1 -- cgit v1.2.3