Skip to content

Commit

Permalink
echo-join: fix regression: 07df59b
Browse files Browse the repository at this point in the history
  • Loading branch information
balupton committed Jan 24, 2024
1 parent 2bbaa0d commit 19ef478
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 23 deletions.
1 change: 1 addition & 0 deletions commands.beta/echo-if-empty
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ function echo_if_empty() (
shift $#
break
;;
'--'*) option_args+=("$item") ;;
*)
if test "$option_fallback" = "$rand"; then
option_fallback="$item"
Expand Down
1 change: 1 addition & 0 deletions commands/contains-line
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ function contains_line() (
shift $#
break
;;
'--'*) option_args+=("$item") ;;
*)
if test "${#option_needles[@]}" -eq 0; then
option_needles+=("$item")
Expand Down
48 changes: 25 additions & 23 deletions commands/echo-join
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
#!/usr/bin/env bash

function echo_join_test() (
source "$DOROTHY/sources/bash.bash"
echo-segment --h1="TEST: $0"

eval-tester --stdout='a b' -- echo-join -- a b

eval-tester --stdout='a, b' -- echo-join ', ' -- a b

eval-tester --stdout=$'a\n\tb' -- echo-join --join=$'\n\t' -- a b

echo-lines -- a b | eval-tester --stdout='a b' -- echo-join --stdin

echo-lines -- a b | eval-tester --stdout='a, b' -- echo-join ', ' --stdin

echo-lines -- a b | eval-tester --stdout=$'a\n\tb' -- echo-join --join=$'\n\t' --stdin

echo-segment --g1="TEST: $0"
return 0
)
function echo_join() (
source "$DOROTHY/sources/stdinargs.bash"

Expand All @@ -21,28 +40,6 @@ function echo_join() (
$(stdinargs_options_help --)
EXAMPLES:
echo-join -- a b
a b
# exit status: 0
echo-join '' -- a b
ab
# exit status: 0
echo-join ', ' -- a b
a, b
# exit status: 0
echo-lines -- a b | echo-join ', ' --stdin
a, b
# exit status: 0
QUIRKS:
There will be no newline at the end, in case you your input or <join> contains newlines, we do not wish to mangle your intention.
EOF
Expand All @@ -67,6 +64,7 @@ function echo_join() (
shift $#
break
;;
'--'*) option_args+=("$item") ;;
*)
if test "$option_join" = "$rand"; then
option_join="$item"
Expand Down Expand Up @@ -105,5 +103,9 @@ function echo_join() (

# fire if invoked standalone
if test "$0" = "${BASH_SOURCE[0]}"; then
echo_join "$@"
if test "$*" = '--test'; then
echo_join_test
else
echo_join "$@"
fi
fi
1 change: 1 addition & 0 deletions commands/echo-lines-after
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ function echo_lines_after() (
shift $#
break
;;
'--'*) option_args+=("$item") ;;
*)
if test "${#option_needles[@]}" -eq 0; then
option_needles+=("$item")
Expand Down
1 change: 1 addition & 0 deletions commands/echo-lines-before
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ function echo_lines_before() (
shift $#
break
;;
'--'*) option_args+=("$item") ;;
*)
if test "${#option_needles[@]}" -eq 0; then
option_needles+=("$item")
Expand Down
1 change: 1 addition & 0 deletions commands/echo-split
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ function echo_split() (
shift $#
break
;;
'--'*) option_args+=("$item") ;;
*)
if test "${#option_needles[@]}" -eq 0; then
option_needles+=("$item")
Expand Down
1 change: 1 addition & 0 deletions commands/nvm-env
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ function nvm_env() (

# convert to quoted string if not already quoted
local cmd_exec
set -x
if test "${#option_cmd[@]}" -eq 1; then
cmd_exec="${option_cmd[0]}"
else
Expand Down

0 comments on commit 19ef478

Please sign in to comment.