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

Support ${@} in Duckscript tasks #667

Closed
MartinKavik opened this issue Jun 27, 2022 · 4 comments
Closed

Support ${@} in Duckscript tasks #667

MartinKavik opened this issue Jun 27, 2022 · 4 comments
Assignees
Milestone

Comments

@MartinKavik
Copy link
Contributor

Feature Description

Support ${@} in Duckscript tasks

Describe The Solution You'd Like

It would be nice to use ${@} in tasks written in Duckscript to pass an array of task arguments.

Code Sample

My current ugly task definition:

[tasks.in_examples]
description = '''
Run chosen task for each example in its root.
Ex: 'makers in_examples mzoon -- -V' or `makers in_examples mzoon build"
'''
script = [
'''
#!@duckscript
handle = glob_array examples/*/Makefile.toml
for path in ${handle}
    example_root = dirname ${path}
    echo Example root: ${example_root}
    if is_defined 5
        exec --fail-on-error makers --cwd ${example_root} ${1} ${2} ${3} ${4} ${5}
    elseif is_defined 4
        exec --fail-on-error makers --cwd ${example_root} ${1} ${2} ${3} ${4}
    elseif is_defined 3
        exec --fail-on-error makers --cwd ${example_root} ${1} ${2} ${3}
    elseif is_defined 2
        exec --fail-on-error makers --cwd ${example_root} ${1} ${2}
    elseif is_defined 1
        exec --fail-on-error makers --cwd ${example_root} ${1}
    else
        exec --fail-on-error makers --cwd ${example_root}
    end
end
'''
]

The future refactored code with #{@}:

[tasks.in_examples]
description = '''
Run chosen task for each example in its root.
Ex: 'makers in_examples mzoon -- -V' or `makers in_examples mzoon build"
'''
script = [
'''
#!@duckscript
handle = glob_array examples/*/Makefile.toml
for path in ${handle}
    example_root = dirname ${path}
    echo Example root: ${example_root}
    exec --fail-on-error makers --cwd ${example_root} ${@}
end
'''
]

Related question:
Can we somehow use an array as arguments? E.g. exec --fail-on-error makers --cwd ${example_root} ..${arr}

Thank you.

@sagiegurari
Copy link
Owner

good idea. I'll check it out. should be simple.

as for the array question, use %{array} instead of ${array}

@sagiegurari
Copy link
Owner

for the array, just to be clear you first need to join to a string using space char and than do that which will split it to args via spaces.
if you need an example tell me.

@MartinKavik
Copy link
Contributor Author

for the array, just to be clear you first need to join to a string using space char and than do that which will split it to args via spaces.

args = array ${1} ${2} ${3} ${4} ${5}
args_string = array_join ${args} " "
# ...
   exec --fail-on-error makers --cwd ${example_root} %{args_string}

^ this seems to work. ${x}s are still ugly but the code is much better now. Thanks.

@sagiegurari
Copy link
Owner

@MartinKavik this is now released. if there are issues feel free to reopen. thanks for the idea.

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

2 participants