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

Add missing File::PATH_SEPARATOR constant #11305

Open
postmodern opened this issue Oct 11, 2021 · 3 comments
Open

Add missing File::PATH_SEPARATOR constant #11305

postmodern opened this issue Oct 11, 2021 · 3 comments

Comments

@postmodern
Copy link
Contributor

Feature Request

It would be useful to have an OS aware File::PATH_SEPARATOR constant. Unlike the regular File::SEPARATOR constant, this constant represents the character used to separate directories in the $PATH environment variable. On Windows the path separator is ';', where as on *nix systems it is ':'.

Example Code

  PATH_SEPARATOR = {% if flag?(:win32) %}
                     ';'
                   {% else %}
                     ':'
                   {% end %}

  PATH_SEPARATOR_STRING = {% if flag?(:win32) %}
                            ";"
                          {% else %}
                            ":"
                          {% end %}

Usage

paths = ENV.fetch("PATH", "").split(File::SEPARATOR, remove_empty: true)
postmodern added a commit to postmodern/crystal that referenced this issue Oct 11, 2021
* These constants represent the separator character used to separate individual
  directories in the $PATH environment variable.
  On Windows the separator is actually ';', where as on Unix based systems it is ':'.

Resolves crystal-lang#11305
@straight-shoota
Copy link
Member

This constant already exists: Process::PATH_DELIITER

There might be a point that it's not very discoverable in the Process namespace. So we could consider moving it somewhere else.
I think the Path namespace would be a better choice than File, though.

@oprypin
Copy link
Member

oprypin commented Oct 11, 2021

I think Process is the best namespace for it. These aren't actually part of a path in any way and they are needed only to be able to pass this information across processes.
And even if it isn't the best location, the difference isn't enough to justify a move with a deprecation.

@postmodern
Copy link
Contributor Author

It could be put under ENV, since ENV is actually a module and not a constant Hash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants