checking for config file
This commit is contained in:
30
chub/init.go
30
chub/init.go
@@ -1,14 +1,10 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/edindazdarevic/confighub/chub/client"
|
||||
"github.com/edindazdarevic/confighub/chub/globals"
|
||||
homedir "github.com/mitchellh/go-homedir"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
)
|
||||
|
||||
@@ -27,29 +23,3 @@ func initCommand(guid string) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
type config struct {
|
||||
MachineGuid string
|
||||
}
|
||||
|
||||
func saveGuidToHomedir(configuration config) {
|
||||
|
||||
directoryName, err := homedir.Dir()
|
||||
globals.PanicWithStyle("I cannot find your home directory. Are you homeless ? ", err)
|
||||
|
||||
expandedDirectoryName, err := homedir.Expand(directoryName)
|
||||
globals.PanicWithStyle("Cannot know your full path to home directory. Is it a secret ? ", err)
|
||||
|
||||
directory := expandedDirectoryName + globals.RuneToAscii(filepath.Separator) + globals.ConfigurationFolderName
|
||||
if !globals.FileExists(directory) {
|
||||
err = os.Mkdir(directory, globals.ConfigurationFilePermissions)
|
||||
globals.PanicWithStyle("I simply cannot make the directory. Am I alowed to ?", err)
|
||||
}
|
||||
|
||||
configByteContent, err := json.Marshal(configuration)
|
||||
globals.PanicWithStyle("Something is terribly wrong. I am sorry. I am so so sorry. :~(", err)
|
||||
|
||||
err = ioutil.WriteFile(directory+globals.RuneToAscii(filepath.Separator)+globals.ConfigurationFileName, configByteContent, globals.ConfigurationFilePermissions)
|
||||
globals.PanicWithStyle("I cannot write to config file in user directory. How can this be ?", err)
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user