Add init function
This commit is contained in:
parent
abe44c3f92
commit
b044726c96
13
tag.sh
13
tag.sh
|
@ -1,6 +1,7 @@
|
|||
#!/usr/bin/env bash
|
||||
set -ueo pipefail
|
||||
# usage:
|
||||
# - init - create an empty database
|
||||
# - add (tag|filename) $VALUE - adds a new tag or filename of $VALUE
|
||||
# - list (tags|files) - lists all the values in a table
|
||||
# - bytag $TAG - list all files by tag label
|
||||
|
@ -8,12 +9,17 @@ set -ueo pipefail
|
|||
# - listtags $FILENAME - list all tags for $FILENAME
|
||||
|
||||
DB_FILE="tags.db"
|
||||
DB_SCHEMA="database.sql"
|
||||
|
||||
fail() {
|
||||
echo "$1" >&2;
|
||||
exit 1
|
||||
}
|
||||
|
||||
log() {
|
||||
echo "$1"
|
||||
}
|
||||
|
||||
listtags() {
|
||||
# $FILENAME $LIMIT
|
||||
[ -z "$1" ] && fail "No filename supplied."
|
||||
|
@ -32,6 +38,13 @@ listtags() {
|
|||
$ADDITIONAL_QUERY"
|
||||
}
|
||||
|
||||
if [[ "$1" = "init" ]]; then
|
||||
[ -f "$DB_FILE" ] && fail "Database file \"$DB_FILE\" already exists. Aborting."
|
||||
cat "$DB_SCHEMA" | sqlite3 "$DB_FILE"
|
||||
log "Empty database file \"$DB_FILE\" created."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if [[ "$1" = "add" ]]; then
|
||||
shift
|
||||
[ "$1" = "tag" ] && TABLE="tags" && COLUMN="label"
|
||||
|
|
Loading…
Reference in New Issue