parent
d12549e314
commit
610f04c85a
59
config.go
59
config.go
|
@ -17,12 +17,6 @@ import "flag"
|
||||||
import "fmt"
|
import "fmt"
|
||||||
import "runtime"
|
import "runtime"
|
||||||
|
|
||||||
import "github.com/gookit/config"
|
|
||||||
import "github.com/gookit/config/yaml"
|
|
||||||
import "github.com/gookit/config/json"
|
|
||||||
|
|
||||||
// import "github.com/davecgh/go-spew/spew"
|
|
||||||
|
|
||||||
// always override the debugging flag from the command line
|
// always override the debugging flag from the command line
|
||||||
var debugging *bool
|
var debugging *bool
|
||||||
var debugtable *bool
|
var debugtable *bool
|
||||||
|
@ -43,8 +37,8 @@ func parseFlags() {
|
||||||
|
|
||||||
flag.StringVar (&hostname, "hostname", "localhost", "Your full hostname")
|
flag.StringVar (&hostname, "hostname", "localhost", "Your full hostname")
|
||||||
|
|
||||||
height := flag.Int ("height", 600, "Width of the Window")
|
height := flag.Int ("height", 0, "Height of the Window")
|
||||||
width := flag.Int ("width", 400, "Width of the Window")
|
width := flag.Int ("width", 0, "Width of the Window")
|
||||||
debugging = flag.Bool("debugging", false, "Enable debugging")
|
debugging = flag.Bool("debugging", false, "Enable debugging")
|
||||||
debugtable = flag.Bool("debugtable", false, "Enable GUI table debugging")
|
debugtable = flag.Bool("debugtable", false, "Enable GUI table debugging")
|
||||||
nogui := flag.Bool("nogui", false, "Do not display the GUI")
|
nogui := flag.Bool("nogui", false, "Do not display the GUI")
|
||||||
|
@ -62,7 +56,14 @@ func parseFlags() {
|
||||||
onExit(nil)
|
onExit(nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Println("ENABLE width =", *width)
|
if (*width > 100) {
|
||||||
|
log.Println("ENABLE width =", int32(*width))
|
||||||
|
pbC.Width = int32(*width)
|
||||||
|
}
|
||||||
|
if (*height > 100) {
|
||||||
|
log.Println("ENABLE height =", int32(*height))
|
||||||
|
pbC.Height = int32(*height)
|
||||||
|
}
|
||||||
log.Println("ENABLE nogui =", *nogui)
|
log.Println("ENABLE nogui =", *nogui)
|
||||||
log.Println("ENABLE debugging =", *debugging)
|
log.Println("ENABLE debugging =", *debugging)
|
||||||
|
|
||||||
|
@ -75,30 +76,26 @@ func parseFlags() {
|
||||||
}
|
}
|
||||||
// os.Exit(0)
|
// os.Exit(0)
|
||||||
|
|
||||||
config.Set("width", *width)
|
if (hostname == "") {
|
||||||
config.Set("height", height)
|
pbC.Hostname = hostname
|
||||||
config.Set("hostname", hostname)
|
}
|
||||||
config.Set("nogui", *nogui)
|
pbC.Debugging = *debugging
|
||||||
config.Set("debugging", *debugging)
|
pbC.Debugtable = *debugtable
|
||||||
|
|
||||||
log.Println("config.Set width", config.String("width"))
|
log.Println("pbC.Width", pbC.Width)
|
||||||
log.Println("config.Set debugging", config.Bool("debugging"))
|
log.Println("pbC.Debugging", pbC.Debugging)
|
||||||
}
|
}
|
||||||
|
|
||||||
func parseConfig(defaultConfig string) {
|
func parseConfig(defaultConfig string) {
|
||||||
config.WithOptions(config.ParseEnv)
|
|
||||||
parseFlags()
|
parseFlags()
|
||||||
|
|
||||||
log.Println("config.Set width", config.String("width"))
|
log.Println("pbC.width", pbC.Width)
|
||||||
log.Println("config.Set debugging", config.Bool("debugging"))
|
log.Println("pbC.height", pbC.Height)
|
||||||
|
log.Println("pbC.debugging", pbC.Debugging)
|
||||||
|
|
||||||
config.LoadOSEnv([]string{"MAIL"})
|
// config.LoadOSEnv([]string{"MAIL"})
|
||||||
config.LoadOSEnv([]string{"USER"})
|
// config.LoadOSEnv([]string{"USER"})
|
||||||
config.LoadOSEnv([]string{"BUILDDEBUG"})
|
// config.LoadOSEnv([]string{"BUILDDEBUG"})
|
||||||
|
|
||||||
// add driver for support of yaml and json
|
|
||||||
config.AddDriver(yaml.Driver)
|
|
||||||
config.AddDriver(json.Driver)
|
|
||||||
|
|
||||||
// look up the user information to try to figure out where the config file is stored
|
// look up the user information to try to figure out where the config file is stored
|
||||||
user, err := user.Current()
|
user, err := user.Current()
|
||||||
|
@ -110,18 +107,21 @@ func parseConfig(defaultConfig string) {
|
||||||
// place under Linux, MacOS and Windows
|
// place under Linux, MacOS and Windows
|
||||||
if runtime.GOOS == "linux" {
|
if runtime.GOOS == "linux" {
|
||||||
log.Println("OS: Linux")
|
log.Println("OS: Linux")
|
||||||
config.Set("configfile", user.HomeDir + "/.config/cloud-control-panel.json")
|
pbC.Filename = user.HomeDir + "/.config/cloud-control-panel.json"
|
||||||
} else if runtime.GOOS == "windows" {
|
} else if runtime.GOOS == "windows" {
|
||||||
log.Println("OS: Windows")
|
log.Println("OS: Windows")
|
||||||
config.Set("configfile", user.HomeDir + "\\cloud-control-panel.json")
|
pbC.Filename = user.HomeDir + "/.config/cloud-control-panel.json"
|
||||||
|
// config.Set("configfile", user.HomeDir + "\\cloud-control-panel.json")
|
||||||
} else {
|
} else {
|
||||||
log.Println("OS: " + runtime.GOOS)
|
log.Println("OS: " + runtime.GOOS)
|
||||||
config.Set("configfile", user.HomeDir + "/cloud-control-panel.json")
|
pbC.Filename = user.HomeDir + "/cloud-control-panel.json"
|
||||||
|
// config.Set("configfile", user.HomeDir + "/cloud-control-panel.json")
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: load the default config file from the resources dir if the config file doesn't exist yet
|
// TODO: load the default config file from the resources dir if the config file doesn't exist yet
|
||||||
// config.LoadFiles("config.json")
|
// config.LoadFiles("config.json")
|
||||||
|
|
||||||
|
/*
|
||||||
filename := config.String("configfile")
|
filename := config.String("configfile")
|
||||||
config.LoadFiles(filename)
|
config.LoadFiles(filename)
|
||||||
|
|
||||||
|
@ -139,4 +139,5 @@ func parseConfig(defaultConfig string) {
|
||||||
if (config.String("nogui") == "true") {
|
if (config.String("nogui") == "true") {
|
||||||
log.Println("DO NOT DISPLAY THE GUI")
|
log.Println("DO NOT DISPLAY THE GUI")
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
18
main.go
18
main.go
|
@ -7,6 +7,11 @@ import "time"
|
||||||
import "os/user"
|
import "os/user"
|
||||||
import "runtime"
|
import "runtime"
|
||||||
import "runtime/debug"
|
import "runtime/debug"
|
||||||
|
import "github.com/golang/protobuf/jsonpb"
|
||||||
|
// import "github.com/golang/protobuf/proto"
|
||||||
|
|
||||||
|
import "git.wit.com/wit/gui"
|
||||||
|
import pb "git.wit.com/wit/witProtobuf"
|
||||||
|
|
||||||
import "github.com/gookit/config"
|
import "github.com/gookit/config"
|
||||||
import "github.com/gobuffalo/packr"
|
import "github.com/gobuffalo/packr"
|
||||||
|
@ -15,13 +20,6 @@ import "github.com/davecgh/go-spew/spew"
|
||||||
// will try to get this hosts FQDN
|
// will try to get this hosts FQDN
|
||||||
import "github.com/Showmax/go-fqdn"
|
import "github.com/Showmax/go-fqdn"
|
||||||
|
|
||||||
import jsonpb "github.com/golang/protobuf/jsonpb"
|
|
||||||
|
|
||||||
// import "github.com/golang/protobuf/proto"
|
|
||||||
import pb "git.wit.com/wit/witProtobuf"
|
|
||||||
|
|
||||||
import "git.wit.com/wit/gui"
|
|
||||||
|
|
||||||
var GITCOMMIT string // this is passed in as an ldflag
|
var GITCOMMIT string // this is passed in as an ldflag
|
||||||
var GOVERSION string // this is passed in as an ldflag
|
var GOVERSION string // this is passed in as an ldflag
|
||||||
var BUILDTIME string // this is passed in as an ldflag
|
var BUILDTIME string // this is passed in as an ldflag
|
||||||
|
@ -79,12 +77,12 @@ func main() {
|
||||||
packrBox = packr.NewBox("./resources")
|
packrBox = packr.NewBox("./resources")
|
||||||
defaultConfig, _ := packrBox.FindString("cloud.json")
|
defaultConfig, _ := packrBox.FindString("cloud.json")
|
||||||
|
|
||||||
// This will parse the command line and config file
|
|
||||||
parseConfig(defaultConfig)
|
|
||||||
|
|
||||||
pbC = pb.MakeDefaultConfig()
|
pbC = pb.MakeDefaultConfig()
|
||||||
spew.Dump(pbC)
|
spew.Dump(pbC)
|
||||||
|
|
||||||
|
// This will parse the command line and config file
|
||||||
|
parseConfig(defaultConfig)
|
||||||
|
|
||||||
marshaler := &jsonpb.Marshaler{}
|
marshaler := &jsonpb.Marshaler{}
|
||||||
stuff, _ := marshaler.MarshalToString(pbC)
|
stuff, _ := marshaler.MarshalToString(pbC)
|
||||||
log.Println(stuff)
|
log.Println(stuff)
|
||||||
|
|
Loading…
Reference in New Issue