From 4d85c40d8ac5140835c5f75d513f886ae5910da9 Mon Sep 17 00:00:00 2001 From: Silvio Rhatto Date: Sat, 18 Sep 2010 12:40:56 -0300 Subject: Making code that checks for file argument as a common function --- lib/keyringer/functions | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'lib') diff --git a/lib/keyringer/functions b/lib/keyringer/functions index adaf576..24df5af 100644 --- a/lib/keyringer/functions +++ b/lib/keyringer/functions @@ -176,3 +176,37 @@ function keyringer_set_env { exit 1 fi } + +# Get a single argument +function keyringer_get_arg { + if [ -z "$1" ]; then + keyringer_action_usage + exit 1 + fi + + echo $1 +} + +# Get a file argument +function keyringer_get_file { + FILE="`keyringer_filename $1`" + + if [ -z "$FILE" ]; then + keyringer_action_usage + exit 1 + elif [ ! -f "$KEYDIR/$FILE" ]; then + echo "File not found: $KEYDIR/$FILE" + exit 1 + fi +} + +# Run the action usage +function keyringer_action_usage { + if [ "`type -t "keyringer_usage_$BASENAME"`" == "function" ]; then + # Use custom action usage + keyringer_usage_$BASENAME + else + # Default usage + echo "Usage: keyringer $BASENAME " + fi +} -- cgit v1.2.3