add standard argv
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
3be6654765
commit
3203dfbb0e
11
Makefile
11
Makefile
|
@ -1,15 +1,14 @@
|
|||
VERSION = $(shell git describe --tags)
|
||||
|
||||
all:
|
||||
all: build
|
||||
reset
|
||||
./basicwindow
|
||||
|
||||
build:
|
||||
ifeq ($(GO111MODULE),)
|
||||
echo no. you must use GO111MODULE to build here
|
||||
false
|
||||
else
|
||||
-rm -f basicwindow
|
||||
go build -v -x
|
||||
endif
|
||||
GO111MODULE=off go build -v -x \
|
||||
-ldflags "-X main.VERSION=${VERSION}"
|
||||
|
||||
stderr: build
|
||||
echo "writing to /tmp/basicwindow.out"
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"github.com/alexflint/go-arg"
|
||||
)
|
||||
|
||||
/*
|
||||
this parses the command line arguements
|
||||
this enables command line options from other packages like 'gui' and 'log'
|
||||
*/
|
||||
|
||||
var argv args
|
||||
|
||||
type args struct {
|
||||
Demo string `arg:"positional" help:"this is just a demo"`
|
||||
}
|
||||
|
||||
func (a args) Description() string {
|
||||
return `
|
||||
This basicwindow example demonstrates multiple windows
|
||||
`
|
||||
}
|
||||
|
||||
func init() {
|
||||
pp := arg.MustParse(&argv)
|
||||
|
||||
// for very new users or users unfamilar with the command line, this may help them
|
||||
if argv.Demo == "version" || argv.Demo == "help" || argv.Demo == "?" {
|
||||
pp.WriteHelp(os.Stdout)
|
||||
os.Exit(0)
|
||||
}
|
||||
}
|
||||
|
||||
func (args) Version() string {
|
||||
return "basicwindow " + VERSION
|
||||
}
|
|
@ -5,17 +5,11 @@ package main
|
|||
*/
|
||||
|
||||
import (
|
||||
"go.wit.com/dev/alexflint/arg"
|
||||
"go.wit.com/lib/debugger"
|
||||
"go.wit.com/log"
|
||||
)
|
||||
|
||||
var args struct {
|
||||
}
|
||||
|
||||
func init() {
|
||||
arg.MustParse(&args)
|
||||
|
||||
if debugger.ArgDebug() {
|
||||
log.Info("cmd line --debugger == true")
|
||||
go func() {
|
||||
|
|
Loading…
Reference in New Issue