ZON Configuration
I've implemented the ZON configuration file system as discussed in #146.
~A couple of important points before this can be merged:~
~1) This does not build with Zig 0.13.0, as it relies on std.zon for parsing and serializing the ZON file. If we want to keep zigup pinned to a release instead of master we should wait until 0.14.0 is out, which hopefully wont be too long.~
~2) A default configuration file path for Windows has not been decided and is currently TODO. I'm not sure what is best here as I don't use Windows much. Once a decision has been made then I'm happy to implement it.~
~3) Not tested on Windows yet. Once point 2 is done if someone can assist with this that would be perfect, if not I can try it myself.~
Okay! It seems that 0.14.0 has been released, and so we should now start having another look at this PR. The last things to do on this are:
- Decide where to store the ZON config on Windows. An idea I had was
%APPDATA%/zigup/zigup.zon. Thoughts? - Test on Windows
I've rebased this back onto the tip of master, and so can start getting this to a mergeable state any time.
%APPDATA%/zigup/zigup.zon would be fine for windows. There's also std.fs.getAppDataDir if you want to use that instead.
There's also
std.fs.getAppDataDirif you want to use that instead.
This seems like the way to do it. I've added a commit to use this on Windows platforms. I've just done a rudimentary test on Windows. The config file ends up being at path C:\Users\<user>\AppData\Local\zigup\zigup.zon for me, which I think makes sense. zigup is finding the ZON file I placed there and adjusting the install_dir and path_link works as expected.
I've also bumped up the commits here and rebased them onto the tip of master, which included shuffling the XDG_HOME stuff into the Config struct with the rest of the default-path related functions.
All that being said, this should be ready for review now.
Okay, realized there was some overlap between the getHomeDir functions and the XDG home dir stuff. I've taken the liberty to clean up the duplicate code and move the XDG_DATA_HOME code into Config.allocDefaultInstallDir.
With the removal of show-config, I have added an example path_link field setting to the example config in the README, since this will serve as the template for users going forward.
Did a couple tweaks to the PR here but it should be good for review now
Apologies for taking a while to respond. I was thinking about this and going through the readme and had an idea that might make this a bit simpler? I think there's probably only 1, maybe 2 options that zigup users may want to customize via a config file, the "install directory" being the main one. What if instead of a ZON config file that supports setting multiple options, we just have a single optional file for this one option? Also, since there is already an --install-dir option, the user already has a way to specify the installation directory, we're just missing way to tell zigup to retain that option for all future invocations of zigup. So what if we just add a new command-line option to do that? Something like --retain-install-dir? Then user's don't even need to know where this setting is stored, they can just read/write it via the command-line and the actual storage mechanism becomes an implementation detail. We'd also probably want to print this value in zigup's help output moving forward.
This seems like a simpler overall solution to me. We could always enhance this configuration to ZON later though if we add more options? What do you think?
FYI, I went ahead and implemented this as a command-line controlled setting for now in this commit: https://github.com/marler8997/zigup/commit/3de4c861a02b2c2b2a10d4274e082db3175e4d3d, i.e.
zigup get-install-dir
zigup set-install-dir PATH
It feels a bit simpler for the user to have to learn/manage I think.
That is a whole lot simpler for the end user, I agree. I think the only thing missing is a similar way to set the path link