rsspls
rsspls copied to clipboard
Expand tilde in path
It would be handy when support variables were supported in the config. Example:
[rsspls]
output = "$HOME/Downloads"
When this example is currently ran, in the current folder a sub-folder $HOME will be created (and within that folder the sub-folder Downloads will be created).
Also, tilde-expansion would be hando to have:
[rsspls]
output = "~/Downloads"
Now the folder ~ will be created in the current folder.
Also (the 3rd request within this issue), it would be nice if, when the output folder is created, an info-level message was being logged. It doesn't happen very often, and when it happens you might want to know (especially when you made a typo, or used a feature –like say environment variables– which isn't supported 🙈).
The creation of the folder happens here, but at the moment I don't have the opportunity to learn Rust...
It would be handy when support variables were supported in the config. Example:
I'm hesitant to add features only because they're handy, each new feature adds to the complexity of the product and has a maintenance cost, even if only a small one.
Do you have concrete examples of where using environment variables would solve a problem? The $HOME example is one such case but I think that would be better solved using tilde expansion as you mention. An implementation supporting environment variables would necessarily need to:
- Parse paths, detecting references to one or more env vars anywhere in the string.
- Interpolate them to produce the final string.
- Determine which config parameters support env vars (all or only specific ones?).
An alternative would be to generate the configuration with another tool. I described one such example of that in https://github.com/wezm/rsspls/issues/33#issuecomment-1951839129.
With all that in mind the tilde expansion feels like the better feature since it:
- Make configs portable to different users
- Is clear which config parameters it applied to (only paths)
I do have one concern/open question though: will it work/make sense on all supported platforms, including Windows? At the moment the tool can treat paths as mostly opaque, only calling join to create new paths. Probably needs some research into how other tools handle this.
When I said "handy", I might have better said that it was unexpected it wasn't supported: when I tried it (both ~ and $) I was surprised the folder I was expecting was not created. That's also why I suggested to log to the user when a folder is created.
However, I can't think of a reason I would need any other variable than $HOME, so with tilde (~) implemented my use cases are covered.
The thing that is described in #33 sounds like you could better do with Ansible (it supports Ninja-templated configuration).
With Python, I would have used os.path.expanduser and os.path.expandvars. After reading the documentation, I realized it is doing more than I thought. It also expands ~user to the home folder of the specific user (on MacOS it would expand to /Users/user if the user exists).
Looking at the bash documenation of tilde expansion it seems the shell is even providing more functionality. So only replacing ~ with the current users home would probably a good idea.
I guess Windows could also be supported, by learning from the documentation of Python's expanduser:
On Windows, USERPROFILE will be used if set, otherwise a combination of HOMEPATH and HOMEDRIVE will be used. An initial ~user is handled by checking that the last directory component of the current user’s home directory matches USERNAME, and replacing it if so.