Skip to content

Commit

Permalink
Improve blank argument handling in _move().
Browse files Browse the repository at this point in the history
refs gh-343
  • Loading branch information
xwmx committed Oct 12, 2024
1 parent 3cf0766 commit 64a23db
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 3 deletions.
9 changes: 7 additions & 2 deletions nb
Original file line number Diff line number Diff line change
Expand Up @@ -16057,7 +16057,10 @@ _move() {
:
;;
*)
_selectors+=("${1:-}")
if [[ -n "${1:-}" ]]
then
_selectors+=("${1:-}")
fi
;;
esac

Expand All @@ -16081,7 +16084,9 @@ _move() {
else
_source_selectors+=("${_selectors[@]}")
fi
else
elif [[ -z "${_to_target_type:-}" ]] &&
[[ -z "${_reset:-}" ]]
then
_exit_1 _help "move"
fi

Expand Down
37 changes: 36 additions & 1 deletion test/move.bats
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,42 @@ Moved\ to:\ .*[.*Sample\ Folder/5.*].*\ .*Sample\ Folder/Example\ File\ Two.md

# no argument #################################################################

@test "'move' with no arguments exits with status 1." {
@test "'move' with no arguments exits with status 1 and prints help." {
{
"${_NB}" init
"${_NB}" add "example.md" --content "Example content."
"${_NB}" notebooks add "destination"
}

run "${_NB}" move

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

# Exits with 1:

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

# Does not delete file:

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

# Does not create git commit:

cd "${NB_DIR}/home" || return 1
while [[ -n "$(git status --porcelain)" ]]
do
sleep 1
done
! git log | grep '\[nb\] Delete'

# Prints help:

[[ "${lines[0]}" =~ Usage.*\: ]]
[[ "${lines[1]}" =~ nb\ move ]]
}

@test "'move --force' with no arguments exits with status 1 and prints help." {
{
"${_NB}" init
"${_NB}" add "example.md" --content "Example content."
Expand Down

0 comments on commit 64a23db

Please sign in to comment.