Compare commits

...

3 Commits

Author SHA1 Message Date
Jeff Carr 8ecad2c6af go test ? 2025-08-29 10:39:34 -05:00
Jeff Carr 8b32c8d316 change namespace 2025-08-29 07:28:16 -05:00
Jeff Carr 6cc03a124c allows GO libraries to have common args 2025-08-29 07:09:32 -05:00
3 changed files with 40 additions and 2 deletions

21
Makefile Normal file
View File

@ -0,0 +1,21 @@
all:
@echo
@echo
clean:
rm -f go.*
redomod:
rm -f go.*
GO111MODULE= go mod init
GO111MODULE= go mod tidy
test:
go test
vet:
@GO111MODULE=off go vet
@echo this go binary package builds okay
goimports:
goimports -w *.go

2
go.mod
View File

@ -1,4 +1,4 @@
module github.com/alexflint/go-arg
module go.wit.com/dev/alexflint/arg
require (
github.com/alexflint/go-scalar v1.2.0

View File

@ -80,9 +80,26 @@ var ErrVersion = errors.New("version requested by user")
var mustParseExit = os.Exit
var mustParseOut io.Writer = os.Stdout
/*
This allows you to have common arg values defined in a GO package
package 'foo'
function init() {
args.Register(&argsFoo)
}
*/
// This stores the args sent from the GO packages
var register []interface{}
func Register(dest ...interface{}) {
register = append(register, dest...)
}
// MustParse processes command line arguments and exits upon failure
func MustParse(dest ...interface{}) *Parser {
return mustParse(Config{Exit: mustParseExit, Out: mustParseOut}, dest...)
register = append(register, dest...)
return mustParse(Config{Exit: mustParseExit, Out: mustParseOut}, register...)
}
// mustParse is a helper that facilitates testing