From 3e91b7bb9bad5f74c0cc87e072b76229d4c34286 Mon Sep 17 00:00:00 2001 From: hellekin Date: Fri, 24 Oct 2014 00:03:48 -0300 Subject: [PATCH] [cleanup] Document options functions --- tomb | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/tomb b/tomb index 349f1d1..810eeca 100755 --- a/tomb +++ b/tomb @@ -552,27 +552,31 @@ _print "Please report bugs on ." } -# Check an option +# Check whether a commandline option is set. +# +# Synopsis: option_is_set -flag [out] +# +# First argument is the commandline flag (e.g., "-s"). +# If the second argument is present and set to 'out', print out the +# result: either 'set' or 'unset' (useful for if conditions). +# +# Return 0 if is set, 1 otherwise option_is_set() { - # First argument, the commandline flag (i.e. "-s"). - # Second (optional) argument: if "out", command will print it out 'set'/'unset' - # (useful for if conditions). - # Return 0 if is set, 1 otherwise + local -i r # the return code (0 = set, 1 = unset) + [[ -n ${(k)OPTS[$1]} ]]; r=$? - if [[ $2 == out ]]; then - if [[ $r == 0 ]]; then - echo 'set' - else - echo 'unset' - fi - fi + + [[ $2 == "out" ]] && { + [[ $r == 0 ]] && { echo 'set' } || { echo 'unset' } + } + return $r; } -# Get an option value +# Print the option value matching the given flag +# Unique argument is the commandline flag (e.g., "-s"). option_value() { - # First argument, the commandline flag (i.e. "-s"). print -n - "${OPTS[$1]}" }