Skip to content

Add a CLI_ARGS_LIST global variable #2139

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

Open
pd93 opened this issue Mar 26, 2025 · 10 comments · May be fixed by #2140
Open

Add a CLI_ARGS_LIST global variable #2139

pd93 opened this issue Mar 26, 2025 · 10 comments · May be fixed by #2140
Labels
area: ui Changes related to the UI of Task.

Comments

@pd93
Copy link
Member

pd93 commented Mar 26, 2025

Description

When the CLI_ARGS variable was first introduced, Task only had string variables, so the variable was populated with a single string with shell quoted values. Since then we have introduced "any type" variables which means that arrays are now available.

Instead of As well as joining the args together, we should make them available in an array. This makes the individual arguments easier to access and loop through without the user having to do additional processing. If the user wants a single string, they are still able to use a string joining function. However, this also adds the flexibility for users to to process arguments first or choose a separator of their own.

Since this would be a breaking change, we should make this available as an experiment.

Related issues:

Edit: Changed this issue from a proposed experiment to edit an existing variable to a feature request for a new variable. This means it is no longer a breaking change and no longer needs to be an experiment.

@pd93 pd93 added breaking change Changes that are not backward compatible. status: proposed Experimental feature - Pending feedback on proposal. labels Mar 26, 2025
@pd93 pd93 moved this to proposed in Task Experiments Mar 26, 2025
@task-bot
Copy link
Collaborator

This issue has been marked as an experiment proposal! 🧪 It will now enter a period of consultation during which we encourage the community to provide feedback on the proposed design. Please see the experiment workflow documentation for more information on how we release experiments.

@pd93 pd93 linked a pull request Mar 26, 2025 that will close this issue
@andreynering
Copy link
Member

andreynering commented Mar 27, 2025

Hey @pd93,

I understand that having CLI_ARGS as an array would be very useful, but I think we should have them both: as a string and as an array.

Keeping the full string is useful because makes it extremelly easy to append to a command like docker {{.CLI_ARGS}}, which otherwise would have to be {{join " " .CLI_ARGS}}.

Also, keeping the existing as is means we wouldn't be breaking the compatibility unnecessarily.

What do you think?

@pd93
Copy link
Member Author

pd93 commented Mar 27, 2025

@andreynering I'm not against having both. I think intuitively, I have always had the assumption that CLI_ARGS would be an array, but I do have several projects where I also use it directly as a string.

How would you handle naming?

@andreynering
Copy link
Member

There are only two hard things in Computer Science: cache invalidation and naming things.

@pd93 That's the challenge 😂

I don't think I have a good name on top of my head at the moment. CLI_ARGS_LIST or CLI_ARGS_ARR look a bit verbose, but are possible candidates.

@trulede
Copy link
Contributor

trulede commented Mar 31, 2025

How about templating command to convert a "string argument list" to an "array of strings"? Then you could use that function whenever you need such a thing. You might even be able to use an existing function such as regexSplit.

@pd93
Copy link
Member Author

pd93 commented Mar 31, 2025

@trulede This already exists. See splitArgs as described in my comment on the related issue.

@vmaerten
Copy link
Member

Keeping the full string is useful because makes it extremelly useful to append to a command like docker {{.CLI_ARGS}}, which otherwise would have to be {{join " " .CLI_ARGS}}.

I totally agree with this. I use this a lot !

Having both seems the best solution

@trulede
Copy link
Contributor

trulede commented Mar 31, 2025

@trulede This already exists. See splitArgs as described in my comment on the related issue.

IMHO just use that templating function. It's easy enough, and more useful, if such things are left in the hands of users to process these things as they need.

@cjlarose
Copy link

cjlarose commented Apr 2, 2025

@trulede I urge you to empathize with users, especially new users like myself. It's not at all obvious in any way that CLI_ARGS is a string containing the quoted shell arguments and not knowing that can introduce subtle bugs. As it stands, CLI_ARGS is a bit of a footgun, especially when combined with things like for:, which accept either an array or a string.

@andreynering I like the idea of having both and removing the need for a breaking change. It would mirror the behavior we see in POSIX shells, including Bash. From the Bash man page

*

Expands to the positional parameters, starting from one. When the expansion occurs within double quotes, it expands to a single word with the value of each parameter separated by the first character of the IFS special variable. That is, "$*" is equivalent to "$1c$2c...", where c is the first character of the value of the IFS variable. If IFS is unset, the parameters are separated by spaces. If IFS is null, the parameters are joined without intervening separators.

@

Expands to the positional parameters, starting from one. When the expansion occurs within double quotes, each parameter expands to a separate word. That is, "$@" is equivalent to "$1" "$2" ... If the double-quoted expansion occurs within a word, the expansion of the first parameter is joined with the beginning part of the original word, and the expansion of the last parameter is joined with the last part of the original word. When there are no positional parameters, "$@" and $@ expand to nothing (i.e., they are removed).

CLI_ARGS_LIST or CLI_ARGS_ARR both seem acceptable (certainly better than $@ 😂 )

@pd93 pd93 added area: ui Changes related to the UI of Task. and removed breaking change Changes that are not backward compatible. status: proposed Experimental feature - Pending feedback on proposal. labels Apr 22, 2025
@pd93 pd93 removed the status in Task Experiments Apr 22, 2025
@pd93 pd93 removed this from Task Experiments Apr 22, 2025
@pd93 pd93 changed the title Split CLI args experiment Add a CLI_ARGS_LIST global variable Apr 22, 2025
@pd93
Copy link
Member Author

pd93 commented Apr 22, 2025

The consensus here was to create a new variable, so I have updated #2140 and the title/description in this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: ui Changes related to the UI of Task.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants