Skip to content

Commit

Permalink
Corrected passing multiple args.
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-ptabor committed Sep 6, 2023
1 parent 1095b74 commit 3454df4
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 7 deletions.
19 changes: 18 additions & 1 deletion examples/location_expansion/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,33 @@ genrule(
name = "app_cmd",
srcs = [],
outs = ["app_cmd.txt"],
cmd = "echo $(rootpaths :test.bash) > \"$@\"",
cmd = """
echo $(rootpaths :test.bash) > "$@"
echo "a1" >> "$@"
echo "a2 b2" >> "$@"
echo " a3\tb3 " >> "$@"
""",
tools = [
":test.bash",
],
)

genrule(
name = "app_entrypoint",
srcs = [],
outs = ["app_entrypoint.txt"],
cmd = """
echo "env" > "$@"
echo "-" >> "$@"
""",
tools = [],
)

oci_image(
name = "image",
base = "@ubuntu",
cmd = ":app_cmd",
entrypoint = ":app_entrypoint",
tars = [":app"],
)

Expand Down
10 changes: 9 additions & 1 deletion examples/location_expansion/test.bash
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
echo "hello world!"
#/bin/bash
echo "hello world!"

args=("$@")
ELEMENTS=${#args[@]}
for (( i=0;i<$ELEMENTS;i++)); do
val="${args[${i}]}"
echo "arg ${i}:${val}"
done
7 changes: 4 additions & 3 deletions examples/location_expansion/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ schemaVersion: "2.0.0"
commandTests:
- name: "echo hello"
command: "bash"
args: ["examples/location_expansion/test.bash"]
expectedOutput: ["hello world!"]
args: ["examples/location_expansion/test.bash", "x", "y", "l1\nl2"]
expectedOutput: ["hello world!", "arg 0:x", "arg 1:y", "arg 2:l1", "l2"]

metadataTest:
cmd: ["examples/location_expansion/test.bash"]
cmd: ["examples/location_expansion/test.bash", "a1", "a2 b2", " a3\tb3 "]
entrypoint: ["env", "-"]
9 changes: 7 additions & 2 deletions oci/private/image.sh.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,20 @@ for ARG in "$@"; do
done <"${ARG#--annotations-file=}"
;;
(--cmd-file=*)
FIXED_ARGS+=("--cmd=$(<"${ARG#--cmd-file=}")")
while IFS= read -r in || [ -n "$in" ]; do
FIXED_ARGS+=("--cmd=$in")
done <"${ARG#--cmd-file=}"
;;
(--entrypoint-file=*)
FIXED_ARGS+=("--entrypoint=$(<"${ARG#--entrypoint-file=}")")
while IFS= read -r in || [ -n "$in" ]; do
FIXED_ARGS+=("--entrypoint=$in")
done <"${ARG#--entrypoint-file=}"
;;
(*) FIXED_ARGS+=( "${ARG}" )
esac
done

echo "!!!: ${CRANE}" "${FIXED_ARGS[@]}"
REF=$("${CRANE}" "${FIXED_ARGS[@]}")

if [ ${#ENV_EXPANSIONS[@]} -ne 0 ]; then
Expand Down

0 comments on commit 3454df4

Please sign in to comment.