Allow to export note to stdout

This commit is contained in:
Konstantin Nazarov 2021-08-22 17:04:50 +01:00
parent fbc7dea378
commit c533bba79f
Signed by: knazarov
GPG key ID: 4CFE0A42FA409C22
2 changed files with 24 additions and 2 deletions

View file

@ -533,7 +533,15 @@ export_note() {
FILENAME="$(assert_find_file_by_id "$ID")" FILENAME="$(assert_find_file_by_id "$ID")"
DIR="$2" DIR="$2"
unpack_mime "$FILENAME" "$DIR" if [ -z "$DIR" ]; then
DIR="$(mktemp -d)"
unpack_mime "$FILENAME" "$DIR"
cat "$DIR/note.md"
rm -rf "$DIR"
else
unpack_mime "$FILENAME" "$DIR"
fi
} }
get_raw_graph() { get_raw_graph() {
@ -620,7 +628,7 @@ while (( "$#" )); do
exit 0 exit 0
;; ;;
-E|--export) -E|--export)
if [ -z "$2" ] || [ -z "$3" ]; then if [ -z "$2" ]; then
echo "Misssing arguments for $1" echo "Misssing arguments for $1"
exit 1 exit 1
fi fi

14
test.sh
View file

@ -147,6 +147,19 @@ export_note() {
assert 'cat out/note.md | grep Subject' "Subject: header1" assert 'cat out/note.md | grep Subject' "Subject: header1"
} }
export_note_stdout() {
"$BASE_DIR/notes.sh" -n <<- EOF
Subject: header1
# This is a body
EOF
NOTE_ID="$(cat "$(pwd)/notes/cur"/* | grep X-Note-Id | cut -d ' ' -f 2)"
MD="$("$BASE_DIR/notes.sh" -E "$NOTE_ID")"
assert 'echo "$MD" | grep Subject' "Subject: header1"
}
edit_note() { edit_note() {
"$BASE_DIR/notes.sh" -n <<- EOF "$BASE_DIR/notes.sh" -n <<- EOF
Subject: header1 Subject: header1
@ -460,6 +473,7 @@ testcase new_note_from_file
testcase new_note_from_dir testcase new_note_from_dir
testcase list_notes testcase list_notes
testcase export_note testcase export_note
testcase export_note_stdout
testcase edit_note testcase edit_note
testcase edit_note_add_file testcase edit_note_add_file
testcase edit_note_no_modifications testcase edit_note_no_modifications