From 42d240c6c165ea7e86826fb35ba43b339109febb Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Mon, 1 Jan 2024 19:22:04 -0600 Subject: [PATCH] add Register() --- parse.go | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/parse.go b/parse.go index 169e8cc..50e3098 100644 --- a/parse.go +++ b/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 {