override the config file from the cmdline for debugging
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
3238695374
commit
d9633fe2db
49
config.go
49
config.go
|
@ -23,6 +23,9 @@ import "github.com/gookit/config/json"
|
|||
|
||||
// import "github.com/davecgh/go-spew/spew"
|
||||
|
||||
// always override the debugging flag from the command line
|
||||
var debugging *bool
|
||||
|
||||
var customUsage = func() {
|
||||
fmt.Fprintf(flag.CommandLine.Output(), "Usage of %s:\n", os.Args[0])
|
||||
flag.PrintDefaults()
|
||||
|
@ -35,21 +38,17 @@ var customUsage = func() {
|
|||
}
|
||||
|
||||
func parseFlags() {
|
||||
var version string
|
||||
var nogui bool
|
||||
var debugging bool
|
||||
var hostname string
|
||||
var width int
|
||||
var height int
|
||||
var version string
|
||||
var hostname string
|
||||
var height int
|
||||
|
||||
flag.StringVar (&version, "version", "v0.1", "Set compiled in version string")
|
||||
|
||||
flag.StringVar (&hostname, "hostname", "localhost", "Your full hostname")
|
||||
flag.IntVar (&width, "width", 400, "Width of the Window")
|
||||
flag.IntVar (&height, "height", 600, "Height of the Window")
|
||||
|
||||
flag.BoolVar (&nogui, "nogui", nogui, "Do not display the GUI")
|
||||
flag.BoolVar (&debugging, "debugging", debugging, "Enable debugging")
|
||||
width := flag.Int ("width", 400, "Width of the Window")
|
||||
debugging = flag.Bool("debugging", false, "Enable debugging")
|
||||
nogui := flag.Bool("nogui", false, "Do not display the GUI")
|
||||
|
||||
// Set the output if something fails to stdout rather than stderr
|
||||
flag.CommandLine.SetOutput(os.Stdout)
|
||||
|
@ -61,25 +60,38 @@ func parseFlags() {
|
|||
log.Println("flag.Parse() worked")
|
||||
} else {
|
||||
log.Println("flag.Parse() failed")
|
||||
onExit(nil)
|
||||
}
|
||||
|
||||
if (debugging == true) {
|
||||
log.Println("ENABLE DEBUG", debugging)
|
||||
log.Println("ENABLE width =", *width)
|
||||
log.Println("ENABLE nogui =", *nogui)
|
||||
log.Println("ENABLE debugging =", *debugging)
|
||||
|
||||
// if (debugging == true) {
|
||||
if (*debugging) {
|
||||
log.Println("ENABLE width =", *width)
|
||||
log.Println("ENABLE debugging =", *debugging)
|
||||
} else {
|
||||
log.Println("DISABLE DEBUG", debugging)
|
||||
log.Println("DISABLE DEBUG debugging =", *debugging)
|
||||
}
|
||||
// os.Exit(0)
|
||||
|
||||
config.Set("width", width)
|
||||
config.Set("width", *width)
|
||||
config.Set("height", height)
|
||||
config.Set("hostname", hostname)
|
||||
config.Set("nogui", nogui)
|
||||
config.Set("debugging", debugging)
|
||||
config.Set("nogui", *nogui)
|
||||
config.Set("debugging", *debugging)
|
||||
log.Println("config.Set width", config.String("width"))
|
||||
log.Println("config.Set debugging", config.Bool("debugging"))
|
||||
}
|
||||
|
||||
func parseConfig(defaultConfig string) {
|
||||
config.WithOptions(config.ParseEnv)
|
||||
parseFlags()
|
||||
|
||||
log.Println("config.Set width", config.String("width"))
|
||||
log.Println("config.Set debugging", config.Bool("debugging"))
|
||||
|
||||
config.LoadOSEnv([]string{"MAIL"})
|
||||
config.LoadOSEnv([]string{"USER"})
|
||||
config.LoadOSEnv([]string{"BUILDDEBUG"})
|
||||
|
@ -113,6 +125,9 @@ func parseConfig(defaultConfig string) {
|
|||
filename := config.String("configfile")
|
||||
config.LoadFiles(filename)
|
||||
|
||||
// always override the debugging flag from the command line
|
||||
config.Set("debugging", *debugging)
|
||||
|
||||
for _, addr := range config.Strings("arr1") {
|
||||
log.Println("addr =", addr)
|
||||
}
|
||||
|
@ -135,7 +150,9 @@ func parseConfig(defaultConfig string) {
|
|||
|
||||
if (config.String("debugging") == "true") {
|
||||
log.Println("ENABLE DEBUG", config.String("debugging"))
|
||||
log.Println("ENABLE DEBUG", config.Bool("debugging"))
|
||||
} else {
|
||||
log.Println("DISABLE DEBUG", config.String("debugging"))
|
||||
log.Println("DISABLE DEBUG", config.Bool("debugging"))
|
||||
}
|
||||
}
|
||||
|
|
24
main.go
24
main.go
|
@ -39,16 +39,19 @@ func onExit(err error) {
|
|||
time.Sleep(1 * 1000 * 1000 * 1000)
|
||||
|
||||
filename := config.String("configfile")
|
||||
log.Println("SAVING CONFIG FILE AS:", filename)
|
||||
if (filename == "") {
|
||||
log.Println("NOT SAVING CONFIG FILE")
|
||||
} else {
|
||||
log.Println("SAVING CONFIG FILE AS:", filename)
|
||||
f, err := os.Create(filename + ".yaml")
|
||||
if err == nil {
|
||||
config.DumpTo(f, "yaml")
|
||||
}
|
||||
|
||||
f, err := os.Create(filename + ".yaml")
|
||||
if err == nil {
|
||||
config.DumpTo(f, "yaml")
|
||||
}
|
||||
|
||||
f, err = os.Create(filename)
|
||||
if err == nil {
|
||||
config.DumpTo(f, "json")
|
||||
f, err = os.Create(filename)
|
||||
if err == nil {
|
||||
config.DumpTo(f, "json")
|
||||
}
|
||||
}
|
||||
|
||||
if (err != nil) {
|
||||
|
@ -91,6 +94,9 @@ func main() {
|
|||
gui.Data.GoVersion = GOVERSION
|
||||
gui.Data.ButtonClickNew = buttonClickNew
|
||||
gui.Data.HomeDir = user.HomeDir
|
||||
gui.Data.Debug = config.Bool("debugging")
|
||||
log.Println("config Bool debugging = ", config.Bool("debugging"))
|
||||
log.Println("gui.Data.Debug = ", gui.Data.Debug)
|
||||
|
||||
// Current User
|
||||
log.Println("Hi " + user.Name + " (id: " + user.Uid + ")")
|
||||
|
|
Loading…
Reference in New Issue