Skip to content

Commit

Permalink
echo-lines: re-add indent, to fix columns
Browse files Browse the repository at this point in the history
/regression 466e239
  • Loading branch information
balupton committed Dec 5, 2023
1 parent e9436d6 commit 957d9ad
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions commands/echo-lines
Original file line number Diff line number Diff line change
Expand Up @@ -40,25 +40,25 @@ function echo_lines_test() (
{
print_line e5
print_line f5
} | eval-tester --name='args indented, ignoring stdin' --stdout=$'xa\nxb\nxc\nxd' \
} | eval-tester --name='args indent, ignoring stdin' --stdout=$'xa\nxb\nxc\nxd' \
-- echo-lines --indent=x -- a b c d

{
print_line e6
print_line f6
} | eval-tester --name='args indented, with stdin' --stdout=$'xa\nxb\nxc\nxd\nxe6\nxf6' \
} | eval-tester --name='args indent, with stdin' --stdout=$'xa\nxb\nxc\nxd\nxe6\nxf6' \
-- echo-lines --stdin --indent=x -- a b c d

{
print_line e7
print_line f7
} | eval-tester --name='args prefixed, ignoring stdin' --stdout=$'--flag=a\n--flag=b\n--flag=c\n--flag=d' \
} | eval-tester --name='args prefix, ignoring stdin' --stdout=$'--flag=a\n--flag=b\n--flag=c\n--flag=d' \
-- echo-lines --prefix='--flag=' -- a b c d

{
print_line e8
print_line f8
} | eval-tester --name='args prefixed, with stdin' --stdout=$'--flag=a\n--flag=b\n--flag=c\n--flag=d\n--flag=e8\n--flag=f8' \
} | eval-tester --name='args prefix, with stdin' --stdout=$'--flag=a\n--flag=b\n--flag=c\n--flag=d\n--flag=e8\n--flag=f8' \
-- echo-lines --stdin --prefix='--flag=' -- a b c d

{
Expand All @@ -76,14 +76,14 @@ function echo_lines_test() (
{
print_line e11
print_line f11
} | eval-tester --name='args prefixed and suffixed, ignoring stdin' --stdout=$'[a]\n[b]\n[c]\n[d]' \
-- echo-lines --prefix='[' --suffix=']' -- a b c d
} | eval-tester --name='args columns, indent, prefix, suffix, ignoring stdin' --stdout=$'x[a]\t[b]\nx[c]\t[d]' \
-- echo-lines --columns=2 --indent='x' --prefix='[' --suffix=']' -- a b c d

{
print_line e12
print_line f12
} | eval-tester --name='args prefixed and suffixed, with stdin' --stdout=$'[a]\n[b]\n[c]\n[d]\n[e12]\n[f12]' \
-- echo-lines --stdin --prefix='[' --suffix=']' -- a b c d
} | eval-tester --name='args columns, indent, prefix, suffix, with stdin' --stdout=$'x[a]\t[b]\nx[c]\t[d]\nx[e12]\t[f12]' \
-- echo-lines --stdin --columns=2 --indent='x' --prefix='[' --suffix=']' -- a b c d

echo-segment --g1="TEST: $0"
return 0
Expand All @@ -106,11 +106,14 @@ function echo_lines() (
--columns=<columns>
output as many arguments per line as there are specified columns
--prefix=<prefix>
--indent=<indent>
prefix each line with this, useful for indentation
--prefix=<prefix>
prefix each input with this
--suffix=<suffix>
suffix each line with this
suffix each input with this
--quoted=<yes/no>
if yes, the arguments will be quoted if necessary
Expand All @@ -124,15 +127,15 @@ function echo_lines() (
}

# process our own arguments, delegate everything else to stdinargs
local item option_columns=1 option_prefix='' option_suffix='' option_quoted='no' args=()
local item option_columns=1 option_indent='' option_prefix='' option_suffix='' option_quoted='no' args=()
while test "$#" -ne 0; do
item="$1"
shift
case "$item" in
'--help' | '-h') help ;;
'--columns='*) option_columns="${item#*--columns=}" ;;
'--prefix='*) option_prefix="${item#*--prefix=}" ;;
'--indent='*) option_prefix="${item#*--indent=}" ;;
'--indent='*) option_indent="${item#*--indent=}" ;;
'--suffix='*) option_suffix="${item#*--suffix=}" ;;
'--no-quoted'* | '--quoted'*)
option_quoted="$(get-flag-value quoted --missing="$option_quoted" -- "$item" | echo-affirmative --stdin)"
Expand All @@ -154,6 +157,9 @@ function echo_lines() (
for ((column = 1; column < "$option_columns"; column++)); do
format="%s\t$format"
done
if test -n "$option_indent"; then
format="$option_indent$format"
fi

# quote the arguments if desired
local lines=()
Expand Down

0 comments on commit 957d9ad

Please sign in to comment.