mirror of
https://github.com/rwinkhart/MUTN.git
synced 2026-09-03 15:47:23 -04:00
Implement temporary "init" functionality
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
package offline
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
)
|
||||
|
||||
func TempInit(configFileMap map[string]string) {
|
||||
// create EntryRoot and ConfigDir
|
||||
dirInit()
|
||||
|
||||
// remove existing config file
|
||||
err := os.Remove(ConfigPath)
|
||||
if err != nil {
|
||||
// ignore error if file does not exist
|
||||
if !os.IsNotExist(err) {
|
||||
fmt.Println(AnsiError + "Failed to remove existing libmutton.ini:" + err.Error() + AnsiReset)
|
||||
}
|
||||
}
|
||||
|
||||
// ensure textEditor is set
|
||||
if configFileMap["textEditor"] == "" {
|
||||
textEditor := os.Getenv("EDITOR")
|
||||
if textEditor == "" {
|
||||
textEditor = fallbackEditor
|
||||
}
|
||||
configFileMap["textEditor"] = textEditor
|
||||
}
|
||||
|
||||
// create and write config file
|
||||
configFile, _ := os.OpenFile(ConfigPath, os.O_CREATE|os.O_WRONLY, 0600)
|
||||
defer configFile.Close()
|
||||
configFile.WriteString("[LIBMUTTON]\n")
|
||||
for key, value := range configFileMap {
|
||||
configFile.WriteString(key + " = " + value + "\n")
|
||||
}
|
||||
|
||||
os.Exit(0)
|
||||
}
|
||||
Reference in New Issue
Block a user