parent
530fcb84d4
commit
0af6f25365
20
parse.go
20
parse.go
|
@ -79,11 +79,29 @@ var ErrVersion = errors.New("version requested by user")
|
||||||
// for monkey patching in example code
|
// for monkey patching in example code
|
||||||
var mustParseExit = os.Exit
|
var mustParseExit = os.Exit
|
||||||
|
|
||||||
|
// This stores the args sent from modules
|
||||||
|
var register []interface{}
|
||||||
|
|
||||||
|
/*
|
||||||
|
Use this in your packages to register
|
||||||
|
variables with go-arg. Then add this to your init()
|
||||||
|
|
||||||
|
package 'foo'
|
||||||
|
function init() {
|
||||||
|
args.Register(&argsFoo)
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
func Register(dest ...interface{}) {
|
||||||
|
register = append(register, dest...)
|
||||||
|
}
|
||||||
|
|
||||||
// MustParse processes command line arguments and exits upon failure
|
// MustParse processes command line arguments and exits upon failure
|
||||||
func MustParse(dest ...interface{}) *Parser {
|
func MustParse(dest ...interface{}) *Parser {
|
||||||
return mustParse(Config{Exit: mustParseExit}, dest...)
|
register = append(register, dest...)
|
||||||
|
return mustParse(Config{Exit: mustParseExit}, register...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// mustParse is a helper that facilitates testing
|
// mustParse is a helper that facilitates testing
|
||||||
func mustParse(config Config, dest ...interface{}) *Parser {
|
func mustParse(config Config, dest ...interface{}) *Parser {
|
||||||
if config.Exit == nil {
|
if config.Exit == nil {
|
||||||
|
|
Loading…
Reference in New Issue