smarter debugging

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2019-05-29 12:46:44 -07:00
parent 6a65efc40d
commit 6ac24113b5
2 changed files with 20 additions and 10 deletions

View File

@ -44,13 +44,15 @@ update:
go get -v -t -u .
# make the json config file human readable
json-make-readable:
config-make-readable:
cat ~/.config/cloud-control-panel.json |jq -r --tab
json-restore:
config-load-testconfig:
echo loading the test config
cp resources/cloud-control-panel.json ~/.config/cloud-control-panel.json
json-delete:
config-delete:
echo deleting your current config
mv ~/.config/cloud-control-panel.json /tmp
diff:

View File

@ -5,7 +5,7 @@ package main
package called 'flag'. This can be used as a simple template to parse
command line arguments in other programs.
It puts everything in the 'config' package which I think is a good
It puts everything in a 'config' Protobuf which I think is a good
wrapper around the 'flags' package and doesn't need a whole mess of
global variables
*/
@ -42,13 +42,13 @@ func loadConfigFile() {
filename := ""
// TODO: confirm this is correct for MacOS and Windows
if runtime.GOOS == "linux" {
log.Println("OS: Linux")
log.Println("loadConfigFile() OS: Linux")
filename = user.HomeDir + "/.config/cloud-control-panel.json"
} else if runtime.GOOS == "windows" {
log.Println("OS: Windows")
log.Println("loadConfigFile() OS: Windows")
filename = user.HomeDir + "\\cloud-control-panel.json"
} else {
log.Println("OS: " + runtime.GOOS)
log.Println("loadConfigFile() OS: " + runtime.GOOS)
filename = user.HomeDir + "/.cloud-control-panel.json"
}
@ -169,7 +169,7 @@ func loadConfigFromFilename(filename string) pb.Config {
}
// will load the default config from within the go binary
func loadDefaultConfig() pb.Config {
func loadDefaultConfig() *pb.Config {
log.Println("TRY TO LOAD DEFAULT CONFIG")
// defaultConfig, _ := packrBox.FindString("protobuf-config.json")
b, err := packrBox.FindString("cloud-control-panel.json")
@ -183,7 +183,7 @@ func loadDefaultConfig() pb.Config {
log.Println("jsonpb.Unmarshal() ERROR =", err)
}
spew.Dump(sets)
return sets
return &sets
}
//
@ -205,5 +205,13 @@ func parseConfig() {
log.Println("account = ", key, foo)
log.Println("Accounts[key] = ", config.Accounts[key])
}
// os.Exit(0)
if (config.Accounts == nil) {
log.Println("loadConfigFile() config.Accounts == nil")
log.Println("If debugging is on, should load default config here")
if (config.Debug) {
log.Println("Debugging is on, loading debug config")
config = loadDefaultConfig()
// onExit(fmt.Errorf("loadConfigFile() config.Accounts == nil"))
}
}
}