Add an option to save the API key to the global WakaTime config if it isn't already there (currently only loading)
simonSlamka opened this issue · comments
Scan the user home directory, looking for the .wakatime.cfg
file. If it isn't there, create it. If it is there, check if it contains an API key. If it does, do nothing. If it doesn't, ask the user to input it and save it in there as api_key=<apiKey>
.
I believe the correct approach, in this case, would be to
- Check if the file exists
- If it does not, create it and write in two lines - [settings] and under it api_key = (API key)
- if it does, read the file, looking for the line containing api_key
- if said line exists, rewrite it with the new setting
- if it does not exist, look for the line containing [settings]
- if this line does exist, insert the API key under it
- if it does not, do step 2 at the
endtop of the file - save and close file
[settings]
should always be at the top
But yeah, you're right. I forgot about the [settings]
descriptor. And if that line exists, I would leave it intact since we don't want to ask for a key on each launch.
It's unlikely to happen that the line would exist without the key value set (api_key=
).
Well, that's true... however, we still should check for it when saving, as the API key has to go under the settings category, as seen here.
I am checking for it in my current fork. Give me a moment and I'll finish it. I know, I said that I forgot about the settings and I'll put them in there.
Added, tested
Nice, glad to be of assistance.