Create file named after isosec

This commit is contained in:
The Magician 2023-12-08 17:01:28 +00:00
parent eeb7f983ae
commit 621340140e
3 changed files with 46 additions and 0 deletions

22
tests/test__zk_new.sh Normal file
View File

@ -0,0 +1,22 @@
#!/bin/bash
TMP_ZETTELKASTEN=""
setup() {
source ../zk
TMP_ZETTELKASTEN="$(mktemp -d)"
}
teardown() {
rm -rf "$TMP_ZETTELKASTEN"
}
test__zk_new_creates_file_in_correct_directory() {
export ZKDIR="$TMP_ZETTELKASTEN"
filename="aaaaaaaaaaaaaa"
fake date "echo $filename"
_zk_new
assert "test -e $TMP_ZETTELKASTEN/$filename"
}

15
tests/test_isosec.sh Normal file
View File

@ -0,0 +1,15 @@
#!/bin/bash
setup() {
source ../zk
}
test_isosec_calls_date_with_correct_parameters() {
expected="date -u +%Y%m%d%H%M%S"
# shellcheck disable=SC2016
fake date echo 'date ${FAKE_PARAMS[@]}'
result="$(_zk_isosec)"
assert_equals "$expected" "$result"
}

9
zk
View File

@ -14,12 +14,21 @@ get_command() {
done done
} }
_zk_isosec() {
date -u +%Y%m%d%H%M%S
}
_zk_list() { _zk_list() {
for zettel in "$ZKDIR"/*; do for zettel in "$ZKDIR"/*; do
echo "$(basename "$zettel") | $(head -1 "$zettel")" echo "$(basename "$zettel") | $(head -1 "$zettel")"
done done
} }
_zk_new() {
filename="$(_zk_isosec)"
touch "$ZKDIR/$filename"
}
main() { main() {
subcommand="$(get_commands "$COMMANDS" "$1")" subcommand="$(get_commands "$COMMANDS" "$1")"
_zk_"$subcommand" _zk_"$subcommand"