Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot use splitArgs and splitLines in for-loops #1822

Closed
stawii opened this issue Sep 19, 2024 · 0 comments
Closed

Cannot use splitArgs and splitLines in for-loops #1822

stawii opened this issue Sep 19, 2024 · 0 comments

Comments

@stawii
Copy link
Contributor

stawii commented Sep 19, 2024

Both splitArgs and splitLines functions returns []string type, which is not []any, causing error:

loop var must be a delimiter-separated string, list or a map

Simple test:

  test-fails:
    vars:
      SOME_LINES: |-
        hello world!
        lorem ipsum
        dolor sit amet

      LINES_LIST:
        ref: splitLines .SOME_LINES
    cmds:
      - cmd: echo LINE {{ q .ITEM }}
        for:
          var: LINES_LIST

Probably wrapping with ANY (pun intended) list function will do the trick. I've checked with:

      LINES_LIST:
        ref: reverse (reverse (splitLines .SOME_LINES))

and:

      LINES_LIST:
        ref: compact (splitLines .SOME_LINES)

both are working and result is as expected:

task: "test-fails" started
task: [test-fails] echo LINE 'hello world!'
LINE hello world!
task: [test-fails] echo LINE 'lorem ipsum'
LINE lorem ipsum
task: [test-fails] echo LINE 'dolor sit amet'
LINE dolor sit amet
task: "test-fails" finished

Please check:

I assume changing case stanza from case []any: to case []any, []string: will solve the issue - but I'm not sure about side effects. EDIT: it doesn't work without type casting, proper code in #1823.

  • Task version: 3.39.2
  • Operating system: MacOS
  • Experiments enabled: no
@task-bot task-bot added the state: needs triage Waiting to be triaged by a maintainer. label Sep 19, 2024
stawii added a commit to stawii/task that referenced this issue Sep 19, 2024
pd93 pushed a commit that referenced this issue Sep 20, 2024
* Update variables.go

Probably solves #1822

* add type casting

* reorder to look better

* add suport for []int functions (until, untilStep)
pd93 added a commit that referenced this issue Sep 20, 2024
@task-bot task-bot removed the state: needs triage Waiting to be triaged by a maintainer. label Sep 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants