From 19ef4787a5008808c8498c259c8f9a62ac223535 Mon Sep 17 00:00:00 2001 From: Benjamin Lupton Date: Wed, 24 Jan 2024 18:23:16 +0800 Subject: [PATCH] echo-join: fix regression: 07df59be8b1923991bbba34f92d794e0bd05a02b --- commands.beta/echo-if-empty | 1 + commands/contains-line | 1 + commands/echo-join | 48 +++++++++++++++++++------------------ commands/echo-lines-after | 1 + commands/echo-lines-before | 1 + commands/echo-split | 1 + commands/nvm-env | 1 + 7 files changed, 31 insertions(+), 23 deletions(-) diff --git a/commands.beta/echo-if-empty b/commands.beta/echo-if-empty index 016145575..a290423ab 100755 --- a/commands.beta/echo-if-empty +++ b/commands.beta/echo-if-empty @@ -59,6 +59,7 @@ function echo_if_empty() ( shift $# break ;; + '--'*) option_args+=("$item") ;; *) if test "$option_fallback" = "$rand"; then option_fallback="$item" diff --git a/commands/contains-line b/commands/contains-line index ed7331ad6..770f3bdc7 100755 --- a/commands/contains-line +++ b/commands/contains-line @@ -54,6 +54,7 @@ function contains_line() ( shift $# break ;; + '--'*) option_args+=("$item") ;; *) if test "${#option_needles[@]}" -eq 0; then option_needles+=("$item") diff --git a/commands/echo-join b/commands/echo-join index 3eb912d5a..2f666a067 100755 --- a/commands/echo-join +++ b/commands/echo-join @@ -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" @@ -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 contains newlines, we do not wish to mangle your intention. EOF @@ -67,6 +64,7 @@ function echo_join() ( shift $# break ;; + '--'*) option_args+=("$item") ;; *) if test "$option_join" = "$rand"; then option_join="$item" @@ -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 diff --git a/commands/echo-lines-after b/commands/echo-lines-after index ffd6b7d47..b739fe0d9 100755 --- a/commands/echo-lines-after +++ b/commands/echo-lines-after @@ -90,6 +90,7 @@ function echo_lines_after() ( shift $# break ;; + '--'*) option_args+=("$item") ;; *) if test "${#option_needles[@]}" -eq 0; then option_needles+=("$item") diff --git a/commands/echo-lines-before b/commands/echo-lines-before index 891e24c05..de32ae65c 100755 --- a/commands/echo-lines-before +++ b/commands/echo-lines-before @@ -90,6 +90,7 @@ function echo_lines_before() ( shift $# break ;; + '--'*) option_args+=("$item") ;; *) if test "${#option_needles[@]}" -eq 0; then option_needles+=("$item") diff --git a/commands/echo-split b/commands/echo-split index 1dda7d1e7..7b23cafbf 100755 --- a/commands/echo-split +++ b/commands/echo-split @@ -53,6 +53,7 @@ function echo_split() ( shift $# break ;; + '--'*) option_args+=("$item") ;; *) if test "${#option_needles[@]}" -eq 0; then option_needles+=("$item") diff --git a/commands/nvm-env b/commands/nvm-env index c1037a7ce..ce4f794f7 100755 --- a/commands/nvm-env +++ b/commands/nvm-env @@ -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