aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorSilvio Rhatto <rhatto@riseup.net>2010-09-18 12:40:56 -0300
committerSilvio Rhatto <rhatto@riseup.net>2010-09-18 12:40:56 -0300
commit4d85c40d8ac5140835c5f75d513f886ae5910da9 (patch)
treefb26d4de4ed2f4ea40f1cd259d5a70baba07469a /lib
parent8d8ceaebb92cb5036c81cc39f711ce72bb942a8d (diff)
downloadkeyringer-4d85c40d8ac5140835c5f75d513f886ae5910da9.tar.gz
keyringer-4d85c40d8ac5140835c5f75d513f886ae5910da9.tar.bz2
Making code that checks for file argument as a common function
Diffstat (limited to 'lib')
-rw-r--r--lib/keyringer/functions34
1 files changed, 34 insertions, 0 deletions
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 <keyring> $BASENAME <file>"
+ fi
+}