task icon indicating copy to clipboard operation
task copied to clipboard

joinEnv - Just like joinPath but with ; for windows else :

Open solvingj opened this issue 4 months ago • 7 comments

Description

Title basically says it all. Once it's possible to prepend paths to the PATH via env (ideally fixed in https://github.com/go-task/task/issues/2034) , it should have a native cross-platform syntax for doing it cleanly on windows or posix platforms.

env:
    PATH: "{{joinEnv "{{.TASKFILE_DIR}}/tools/bin" .PATH}}"

or perhaps

env:
    BIN_DIR: "{{joinPath {{.TASKFILE_DIR}} "tools" "bin"}}"
    PATH: "{{joinEnv .BIN_DIR .PATH}}"

Additionally, or alternatively, add a special variable: PATHSEP for platform specific path separation in env vars.

env:
    PATH: "{{{{.TASKFILE_DIR}}/tools/bin{{.PATHSEP}}{{.PATH}}"

solvingj avatar Sep 01 '25 15:09 solvingj

This sounds like an easy one. Open for community pull requests.

andreynering avatar Sep 02 '25 13:09 andreynering

Happy with this too. A couple of implementation notes:

  • Separators
    • Windows uses ;
    • Linux/MacOS use :
  • I think there is no harm in a "join" function and a variable being added.
  • PATHSEP is highly ambiguous. Something like PATH_ENV_SEPARATOR
    • I prefer clarity over short names
    • _ as a word separator in var names
  • Same for joinEnv. This should be something like joinPathEnv
    • Same reasons for naming as the variable
    • Naming lines up with the variable
  • We don't actually have a FILEPATH_SEPARATOR
    • This could be added for parity
    • Add both to the templating reference docs under system variables.

pd93 avatar Sep 02 '25 14:09 pd93

Agh... there's a func in there defined as os() which breaks importing os.PathListSep. How you want me to deal with it? Rename os()/arch() to goos()/goarch() perhaps?

solvingj avatar Sep 03 '25 01:09 solvingj

I'm interested in working on this issue. Could you provide more context about what you're looking for? Any additional details about requirements or constraints would be helpful.

tysoncung avatar Oct 09 '25 02:10 tysoncung

I'm interested in working on this issue. Could you provide more context about what you're looking for? Any additional details about requirements or constraints would be helpful.

Thanks but the work is done. The implementation details were essentially obvious and confirmed by @andreynering and @pd93 . It's just a matter of them finding time to review and merge.

solvingj avatar Oct 09 '25 13:10 solvingj

" Perhaps this PR is more effort than value."

From the last comment on the PR by the reviewer. Am I to understand the meaning of this is they don't agree that adding this functionality is worthwhile?

CaelFrost avatar Oct 30 '25 17:10 CaelFrost

The two people who green lit it were maintainers, the person who made that comment was a contributor. I think maintainers haven't had time to review/approve/merge feature PRs in a few months. Main commit history just has chores and fixes and such.

solvingj avatar Nov 01 '25 13:11 solvingj