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 enables command line options from other packages like 'gui' and 'log'
*/
import (
"log"
"fmt"
"time"
arg "github.com/alexflint/go-arg"
"go.wit.com/gui"
)
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"`
Foo string
Bar bool
User string `arg:"env:USER"`
Demo bool `help:"run a demo"`
gui.GuiArgs
VerboseDNS bool `arg:"--verbose-dns" help:"debug your dns settings"`
}
func init() {
arg.MustParse(&args)
fmt.Println(args.Foo, args.Bar, args.User)
// fmt.Println(args.Foo, args.Bar, args.User)
if (args.Gui != "") {
gui.GuiArg.Gui = args.Gui
if gui.ArgDebug() {
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.localSleep = 100 * time.Millisecond

View File

@ -2,12 +2,11 @@
package cloudflare
import (
"log"
"encoding/json"
"io/ioutil"
"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("spew dump:")
spew.Dump(records)
// spew.Dump(records)
for _, record := range records.Result {
log.Println("spew record:", record)
log.Println("record:", record.Name, record.ID)

View File

@ -6,6 +6,7 @@ import (
"log"
"go.wit.com/gui"
"go.wit.com/gui/gadgets"
)
// This creates a window
@ -79,8 +80,20 @@ func makeConfigWindow(n *gui.Node) {
grid.NewLabel("Cloudflare API")
grid.NewLabel(url)
hostname := gadgets.NewBasicEntry(grid, "hostname")
zone := gadgets.NewBasicEntry(grid, "domain name")
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 () {
log.Println("getZones()")
GetZones(aw.S, ew.S)

View File

@ -17,8 +17,11 @@ log:
reset
tail -f /tmp/witgui.* /tmp/guilogfile
debug: build
./control-panel-cloudflare --gui-debug
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:
./control-panel-cloudflare >/tmp/witgui.log.stderr 2>&1

View File

@ -1,30 +1,17 @@
// This creates a simple hello world window
package main
/*
this enables command line options from other packages like 'gui' and 'log'
*/
import (
"fmt"
arg "github.com/alexflint/go-arg"
"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() {
arg.MustParse(&args)
fmt.Println(args.Foo, args.Bar, args.User)
if (args.Gui != "") {
gui.GuiArg.Gui = args.Gui
}
log.Log(true, "INIT() args.GuiArg.Gui =", gui.GuiArg.Gui)
arg.MustParse()
log.Bool(true, "INIT() args.ArgDebug =", gui.ArgDebug())
}

View File

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

View File

@ -1,26 +1,21 @@
// This is a simple example
package main
import (
"go.wit.com/log"
"go.wit.com/gui"
"go.wit.com/control-panel-dns/cloudflare"
)
var title string = "Cloudflare DNS Control Panel"
var outfile string = "/tmp/guilogfile"
var configfile string = ".config/wit/cloudflare"
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/"
func main() {
// send all log() output to a file in /tmp
log.SetTmp()
// parse the config file
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())
}