Viv edit config option
Hey Jannis / Tuure,
I had an idea for a little quality-of-life feature I wanted to run by you. Details up for discussion but the basic idea would be to add a --config option or similar to viv. Eg:-
viv --config
It would look for existing configs and if found open it in your default editor. If not, create it for you, and maybe prefill out some default options. Similar to the way you edit your git config, ie:-
git config --global --edit
Rationale here is I forget things and it is a little intimidating to tell users to go hand craft a json file from scratch and put it in a valid location and currently there is no feedback if you do it wrong. With a feature like this, we could tell users to just run viv --config and change setting xxx to true or whatever.
This is something I would work on and submit as a PR. What do you guys think?
Cool idea, I like it!
Creating a file with the default config is also a great idea but it's a bit more complicated than you might guess ^^ Here are my thoughts:
- Ultimately, we probably want to run
$EDITOR <config-path>. This needs to happen inviv, notvivify-server, becausevivify-serverisn't connected to a terminal - We don't want to add a second source of truth for the default config because then we'll have problems maintaining it, and the current single source of truth is in
src/config.ts, meaning the way to access it is fromvivify-server - That said, editing the config with the feature of creating the default config needs to be an interplay between
vivify-serverandviv.
So what I'd probably do is
- Add empty arrays for
stylesandscriptsto thedefault configandexportit - Extend the
src/cli.tswith a new option--print-default-configor something that runsconsole.log(JSON.stringify(defaultConfig, null, 4)) - Add the
--configoption to thevivscript so that- If a config file exists, it just opens it in the editor and exits
- If no config file exists, it runs
vivify-serverthe way it always does at the moment, but then instead ofechoing the outputs it writes them to~/.config/vivify/config.json. Make sure to only redirectsstdoutthere. Then open the file in the editor
Ah and actually we'll also have to think about the same single source of truth thing for the config path(s) and precedence. So in addition to that we should also use vivify-server to resolve the config path and decide whether or not the file exists. I.e. you could adjust the ideas above to
- always call
vivify-server - make the new option in
vivify-serverprint the path of the config file with highest precedence if one exists and otherwise print the default config - work that into
vivby somehow communicating which case we're in, and acting accordingly
make the new option in
vivify-serverprint the path of the config file with highest precedence if one exists and otherwise print the default config
Would this perhaps be two new options?
- Get the config file location based on precedence and if none exists return the location it should be in based on highest precedence
- An option that always returns the default config (might also be useful for a future "reset config" option)
Yes, could be two options but then you'd have to call vivify-server twice and for that we'd have to also change how the server is started because we don't want to go through the whole STARTUP COMPLETED thing and all that twice. Totally possible though, then I'd say we no longer start the server when options like version, --get-default-config or --get-config-path are called and instead just print the answer and quit. That way you could just do something like default_config="$(vivify-server --get-default-config)" in the shell script.