switch to using Register() from 'go-arg'

implement 'universal' use of go-arg

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2023-12-29 17:29:47 -06:00
parent a3dd21aef0
commit 867b69f555
8 changed files with 57 additions and 53 deletions

27
args.go
View File

@ -2,42 +2,31 @@ package main
/* /*
this parses the command line arguements this parses the command line arguements
this enables command line options from other packages like 'gui' and 'log'
*/ */
import ( import (
"log" "log"
"fmt"
"time" "time"
arg "github.com/alexflint/go-arg" arg "github.com/alexflint/go-arg"
"go.wit.com/gui" "go.wit.com/gui"
) )
var args struct { var args struct {
Verbose bool
VerboseNet bool `arg:"--verbose-net" help:"debug your local OS network settings"`
VerboseDNS bool `arg:"--verbose-dns" help:"debug your dns settings"`
LogFile string `help:"write all output to a file"`
// User string `arg:"env:USER"`
Display string `arg:"env:DISPLAY"` Display string `arg:"env:DISPLAY"`
VerboseDNS bool `arg:"--verbose-dns" help:"debug your dns settings"`
Foo string
Bar bool
User string `arg:"env:USER"`
Demo bool `help:"run a demo"`
gui.GuiArgs
} }
func init() { func init() {
arg.MustParse(&args) arg.MustParse(&args)
fmt.Println(args.Foo, args.Bar, args.User) // fmt.Println(args.Foo, args.Bar, args.User)
if (args.Gui != "") { if gui.ArgDebug() {
gui.GuiArg.Gui = args.Gui log.Println(true, "INIT() gui debug == true")
} else {
log.Println(true, "INIT() gui debug == false")
} }
log.Println(true, "INIT() args.GuiArg.Gui =", gui.GuiArg.Gui)
// me.dnsTTL = 2 // how often to recheck DNS
// me.dnsTTLsleep = 0.4 // sleep between loops
me.dnsSleep = 500 * time.Millisecond me.dnsSleep = 500 * time.Millisecond
me.localSleep = 100 * time.Millisecond me.localSleep = 100 * time.Millisecond

View File

@ -2,12 +2,11 @@
package cloudflare package cloudflare
import ( import (
"log"
"encoding/json" "encoding/json"
"io/ioutil" "io/ioutil"
"net/http" "net/http"
"github.com/davecgh/go-spew/spew" "go.wit.com/log"
) )
/* /*
@ -205,7 +204,7 @@ func GetZones(auth, email string) *DNSRecords {
// log.Println("getZones() worked", records) // log.Println("getZones() worked", records)
// log.Println("spew dump:") // log.Println("spew dump:")
spew.Dump(records) // spew.Dump(records)
for _, record := range records.Result { for _, record := range records.Result {
log.Println("spew record:", record) log.Println("spew record:", record)
log.Println("record:", record.Name, record.ID) log.Println("record:", record.Name, record.ID)

View File

@ -6,6 +6,7 @@ import (
"log" "log"
"go.wit.com/gui" "go.wit.com/gui"
"go.wit.com/gui/gadgets"
) )
// This creates a window // This creates a window
@ -79,8 +80,20 @@ func makeConfigWindow(n *gui.Node) {
grid.NewLabel("Cloudflare API") grid.NewLabel("Cloudflare API")
grid.NewLabel(url) grid.NewLabel(url)
hostname := gadgets.NewBasicEntry(grid, "hostname")
zone := gadgets.NewBasicEntry(grid, "domain name")
grid.Pad() grid.Pad()
vb.NewButton("Lookup Hostname", func () {
log.Println("Find all the Resource Records for hostname:", hostname.Get())
log.Println("Find all the Resource Records for zone:", zone.Get())
GetZones(aw.S, ew.S)
for d, v := range Config {
log.Println("Zone =", d, "v =", v)
}
})
vb.NewButton("getZones()", func () { vb.NewButton("getZones()", func () {
log.Println("getZones()") log.Println("getZones()")
GetZones(aw.S, ew.S) GetZones(aw.S, ew.S)

View File

@ -17,8 +17,11 @@ log:
reset reset
tail -f /tmp/witgui.* /tmp/guilogfile tail -f /tmp/witgui.* /tmp/guilogfile
debug: build
./control-panel-cloudflare --gui-debug
gocui: build gocui: build
./control-panel-cloudflare -gui gocui >/tmp/witgui.log.stderr 2>&1 ./control-panel-cloudflare --gui gocui >/tmp/witgui.log.stderr 2>&1
quiet: quiet:
./control-panel-cloudflare >/tmp/witgui.log.stderr 2>&1 ./control-panel-cloudflare >/tmp/witgui.log.stderr 2>&1

View File

@ -1,30 +1,17 @@
// This creates a simple hello world window
package main package main
/*
this enables command line options from other packages like 'gui' and 'log'
*/
import ( import (
"fmt"
arg "github.com/alexflint/go-arg" arg "github.com/alexflint/go-arg"
"go.wit.com/gui" "go.wit.com/gui"
log "go.wit.com/gui/log" "go.wit.com/log"
) )
var args struct {
Foo string
Bar bool
User string `arg:"env:USER"`
Demo bool `help:"run a demo"`
gui.GuiArgs
log.LogArgs
}
func init() { func init() {
arg.MustParse(&args) arg.MustParse()
fmt.Println(args.Foo, args.Bar, args.User) log.Bool(true, "INIT() args.ArgDebug =", gui.ArgDebug())
if (args.Gui != "") {
gui.GuiArg.Gui = args.Gui
}
log.Log(true, "INIT() args.GuiArg.Gui =", gui.GuiArg.Gui)
} }

View File

@ -1,4 +1,3 @@
// This is a simple example
package main package main
import ( import (
@ -10,6 +9,8 @@ import (
"go.wit.com/control-panel-dns/cloudflare" "go.wit.com/control-panel-dns/cloudflare"
) )
var configfile string = ".config/wit/cloudflare"
func saveConfig() { func saveConfig() {
log.Println("TODO") log.Println("TODO")
} }

View File

@ -1,26 +1,21 @@
// This is a simple example
package main package main
import ( import (
"go.wit.com/log"
"go.wit.com/gui" "go.wit.com/gui"
"go.wit.com/control-panel-dns/cloudflare" "go.wit.com/control-panel-dns/cloudflare"
) )
var title string = "Cloudflare DNS Control Panel" var title string = "Cloudflare DNS Control Panel"
var outfile string = "/tmp/guilogfile"
var configfile string = ".config/wit/cloudflare"
var myGui *gui.Node var myGui *gui.Node
// var buttonCounter int = 5
// var gridW int = 5
// var gridH int = 3
// var mainWindow, more, more2 *gui.Node
// var cloudflareURL string = "https://api.cloudflare.com/client/v4/zones/" // var cloudflareURL string = "https://api.cloudflare.com/client/v4/zones/"
func main() { func main() {
// send all log() output to a file in /tmp
log.SetTmp()
// parse the config file // parse the config file
readConfig() readConfig()

View File

@ -0,0 +1,17 @@
package main
/*
this enables command line options from other packages like 'gui' and 'log'
*/
import (
arg "github.com/alexflint/go-arg"
"go.wit.com/gui"
"go.wit.com/log"
)
func init() {
arg.MustParse()
log.Bool(true, "INIT() args.ArgDebug =", gui.ArgDebug())
}