Skip to content

Commit

Permalink
Support multiple --title and --tag options in add.
Browse files Browse the repository at this point in the history
  • Loading branch information
xwmx committed Jul 29, 2021
1 parent 0fa5ee2 commit 7857405
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 37 deletions.
6 changes: 4 additions & 2 deletions nb
Expand Up @@ -10681,7 +10681,8 @@ _add() {
_browse=1
;;
-c|--content)
_option_content="$(_option_get_value "${__arg}" "${__val:-}")"
[[ -n "${_option_content:-}" ]] && _option_content+="${_NEWLINE}${_NEWLINE}"
_option_content+="$(_option_get_value "${__arg}" "${__val:-}")"
_browse_arguments+=("${__arg}" "${__val:-}")
shift
;;
Expand Down Expand Up @@ -10719,7 +10720,8 @@ _add() {
shift
;;
--tag*)
_tag_list="$(_option_get_tags "${__arg}" "${__val:-}")"
[[ -n "${_tag_list:-}" ]] && _tag_list+=" "
_tag_list+="$(_option_get_tags "${__arg}" "${__val:-}")"
_browse_arguments+=("${__arg}" "${__val:-}")
shift
;;
Expand Down
67 changes: 32 additions & 35 deletions test/add.bats
Expand Up @@ -453,35 +453,33 @@ Example: content.\\n")
# content #####################################################################

@test "'add' with piped content includes content from --title and multiple --tags, --content, and arguments separated by newlines." {
skip "TODO"
{
"${_NB}" init
}

echo "Piped content." | {
run "${_NB}" add \
"Argument content one." \
--tags tag1,tag2 \
--title "Example Title" \
--content "Option content one." \
--tags tag3,tag4 \
--content "Option content two." \
"Argument content two."
run "${_NB}" add \
"Argument content one." \
--tags tag1,tag2 \
--title "Example Title" \
--content "Option content one." \
--tags tag3,tag4 \
--content "Option content two." \
"Argument content two." <<< "Piped content."

printf "\${status}: '%s'\\n" "${status}"
printf "\${output}: '%s'\\n" "${output}"
printf "\${status}: '%s'\\n" "${status}"
printf "\${output}: '%s'\\n" "${output}"

# Returns status 0:
# Returns status 0:

[[ "${status}" -eq 0 ]]
[[ "${status}" -eq 0 ]]

# Creates new note file:
# Creates new note file:

[[ -f "${NB_DIR}/home/example_title.markdown" ]]
[[ -f "${NB_DIR}/home/example_title.md" ]]

diff \
<(cat "${NB_DIR}/home/example_title.markdown") \
<(cat <<HEREDOC
diff \
<(cat "${NB_DIR}/home/example_title.md") \
<(cat <<HEREDOC
# Example Title
#tag1 #tag2 #tag3 #tag4
Expand All @@ -496,28 +494,27 @@ Piped content.
HEREDOC
)

# Creates git commit:
# Creates git commit:

cd "${NB_DIR}/home" || return 1
while [[ -n "$(git status --porcelain)" ]]
do
sleep 1
done
git log --stat
git log | grep -q '\[nb\] Add: example_title.markdown'
cd "${NB_DIR}/home" || return 1
while [[ -n "$(git status --porcelain)" ]]
do
sleep 1
done
git log --stat
git log | grep -q '\[nb\] Add: example_title.md'

# Adds to index:
# Adds to index:

[[ -e "${NB_DIR}/home/.index" ]]
[[ -e "${NB_DIR}/home/.index" ]]

diff \
<(ls "${NB_DIR}/home") \
<(cat "${NB_DIR}/home/.index")
diff \
<(ls "${NB_DIR}/home") \
<(cat "${NB_DIR}/home/.index")

# Prints output:
# Prints output:

[[ "${lines[0]}" =~ Added:\ .*[.*1.*].*\ .*example_title.markdown.*\ \"Example\ Title\" ]]
}
[[ "${lines[0]}" =~ Added:\ .*[.*1.*].*\ .*example_title.md.*\ \"Example\ Title\" ]]
}

@test "'add' with piped content includes content from --title and multiple --tags, --content, and arguments separated by newlines and a specified file extension." {
Expand Down

0 comments on commit 7857405

Please sign in to comment.