task icon indicating copy to clipboard operation
task copied to clipboard

Allow for use of `>` to perform string Folding

Open FilBot3 opened this issue 3 years ago • 3 comments

Feature Request

Please allow the use of YAML > folding for strings. Example:

---
# https://taskfile.dev
version: '3'

vars:
  DOCKER: podman

tasks:
  default:
    cmds:
      - echo "Hello, World!"

  build-dev:
    desc: Use Podman/Docker to build the React App.
    cmds:
      - "{{.DOCKER}} run \
          --rm \
          --userns=keep-id \
          --volume=\"$(pwd):/home/node/user:Z\" \
          --workdir=\"/home/node/user\" \
          --entrypoint=\"npm\" \
          docker.io/library/node:16 \
            run build:dev"

  build-prod:
    desc: Use Podman/Docker to build the React App.
    cmds:
      - "{{.DOCKER}} run \
          --rm \
          --userns=keep-id \
          --volume=\"$(pwd):/home/node/user:Z\" \
          --workdir=\"/home/node/user\" \
          --entrypoint=\"npm\" \
          docker.io/library/node:16 \
            run build:prod"

  podman-build:
    desc: Build the Application Container.
    cmds:
      - "{{.DOCKER}} build \
           --file=containers/Dockerfile \
           --tag=localhost/fhirmemberrecordapp:latest \
           ."

  podman-run:
    desc: Run the container for testing.
    cmds:
      - podman run --rm --read-only --env="CONTAINER_DEBUG=true" --env="inject_arg_MRA_API_BASE=philrockssocks" --mount="type=tmpfs,destination=/var/cache/nginx" --mount="type=tmpfs,destination=/usr/share/nginx/html" --entrypoint="/bin/bash" -it localhost/fhirmemberrecordapp:latest

  podman-run2:
    desc: Run the container for testing.
    cmds:
      - >
        podman run 
          --rm 
          --read-only 
          --env="CONTAINER_DEBUG=true" 
          --env="inject_arg_MRA_API_BASE=philrockssocks" 
          --mount="type=tmpfs,destination=/var/cache/nginx" 
          --mount="type=tmpfs,destination=/usr/share/nginx/html" 
          --entrypoint="/bin/bash" 
          -it 
          localhost/fhirmemberrecordapp:latest
...

The second podman-run2 is the desired format. When I've used this, Task doesn't seem to follow that then see's only the first line.

FilBot3 avatar Apr 14 '22 19:04 FilBot3

Which cmd block above is problematic?

ghostsquad avatar Apr 15 '22 03:04 ghostsquad

Which cmd block above is problematic?

The last command: podman-run2 is the one that doesn't run. I get this error:

➜ task podman-run2
task: [podman-run2] podman run
  --rm
  --read-only
  --env="CONTAINER_DEBUG=true"
  --env="inject_arg_MRA_API_BASE=philrockssocks"
  --mount="type=tmpfs,destination=/var/cache/nginx"
  --mount="type=tmpfs,destination=/usr/share/nginx/html"
  --entrypoint="/bin/bash"
  -it
  localhost/fhirmemberrecordapp:latest

Error: requires at least 1 arg(s), only received 0
task: Failed to run task "podman-run2": exit status 125

The expected behavior is that the > "thingy" is supposed to remove all whitespace and replace it with a single space to form a single line.

FilBot3 avatar Apr 15 '22 12:04 FilBot3

I'm getting some inconsistent behavior. And I found several bugs in the upstream yaml package that's used in task:

https://github.com/go-yaml/yaml/issues/827 https://github.com/go-yaml/yaml/issues/804 https://github.com/go-yaml/yaml/issues/789 https://github.com/go-yaml/yaml/issues/387

The fix would be to identify a different yaml package to use that doesn't have this bug (but may also have others), OR wait for a fix upstream.

We should keep this issue open as a reminder to update the dependency when a fix is released, but otherwise, there's nothing much I can do.

Test Case 1

version: '3'
tasks:
  yo:
    cmds:
    - >
      GREETING=hello
      SUBJECT=human
      echo "${GREETING}, ${SUBJECT}"
at 21:42:01 ❯ t yo
task: [yo] GREETING=hello SUBJECT=human echo "${GREETING}, ${SUBJECT}"

Test Case 2

version: '3'
tasks:
  yo:
    cmds:
    - >
      GREETING=hello
      SUBJECT=human

      echo "${GREETING}, ${SUBJECT}"
at 21:41:57 ❯ t yo
task: [yo] GREETING=hello SUBJECT=human
echo "${GREETING}, ${SUBJECT}"

hello, human

Test Case 3

version: '3'
tasks:
  yo:
    cmds:
    - >
      GREETING=hello
      SUBJECT=human
        echo "${GREETING}, ${SUBJECT}"
at 21:41:57 ❯ t yo
task: [yo] GREETING=hello SUBJECT=human
echo "${GREETING}, ${SUBJECT}"

hello, human

Test Case 4

version: '3'
tasks:
  yo:
    cmds:
    - >
      GREETING=hello
      SUBJECT=human
        echo
        "${GREETING}, ${SUBJECT}"
at 21:44:29 ❯ t yo
task: [yo] GREETING=hello SUBJECT=human
  echo
  "${GREETING}, ${SUBJECT}"


"hello, human": executable file not found in $PATH
task: Failed to run task "yo": exit status 127

Test Case 5

version: '3'
tasks:
  yo:
    cmds:
    - >
      GREETING=hello
      SUBJECT=human
        echo \
        "${GREETING}, ${SUBJECT}"
at 21:45:41 ❯ t yo
task: [yo] GREETING=hello SUBJECT=human
  echo \
  "${GREETING}, ${SUBJECT}"

hello, human

ghostsquad avatar Apr 16 '22 04:04 ghostsquad