diff --git a/kong.go b/kong.go index 1b84f38..0a8dc0d 100644 --- a/kong.go +++ b/kong.go @@ -40,6 +40,10 @@ type Kong struct { registry *Registry noDefaultHelp bool help func(*Context) error + + // Set temporarily by Options. These are moved into the Model after build(). + name string + description string } // New creates a new Kong parser on grammar. @@ -63,12 +67,16 @@ func New(grammar interface{}, options ...Option) (*Kong, error) { if err != nil { return k, err } - model.Name = filepath.Base(os.Args[0]) + if k.name == "" { + model.Name = filepath.Base(os.Args[0]) + } else { + model.Name = k.name + } + if k.description != "" { + model.Help = k.description + } k.Model = model - for _, option := range options { - option(k) - } return k, nil } diff --git a/options.go b/options.go index 7e2a871..7020a0b 100644 --- a/options.go +++ b/options.go @@ -6,9 +6,6 @@ import ( ) // Options apply optional changes to the Kong application. -// -// Note that Options are applied twice: once just prior to the grammar is constructed and once after. In the -// former case, Kong.Application will be nil. type Option func(k *Kong) // ExitFunction overrides the function used to terminate. This is useful for testing or interactive use. @@ -26,9 +23,7 @@ func NoDefaultHelp() Option { // Name overrides the application name. func Name(name string) Option { return func(k *Kong) { - if k.Model != nil { - k.Model.Name = name - } + k.name = name } } @@ -55,9 +50,7 @@ func NamedMapper(name string, mapper Mapper) Option { // Description sets the application description. func Description(description string) Option { return func(k *Kong) { - if k.Model != nil { - k.Model.Help = description - } + k.description = description } }