add Register()
This commit is contained in:
parent
bf629a16cb
commit
42d240c6c1
20
parse.go
20
parse.go
|
@ -79,11 +79,29 @@ var ErrVersion = errors.New("version requested by user")
|
|||
// for monkey patching in example code
|
||||
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
|
||||
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
|
||||
func mustParse(config Config, dest ...interface{}) *Parser {
|
||||
if config.Exit == nil {
|
||||
|
|
Loading…
Reference in New Issue