summaryrefslogtreecommitdiff
path: root/parse.go
diff options
context:
space:
mode:
authorSebastiaan Pasterkamp <[email protected]>2022-09-17 12:39:31 +0200
committerSebastiaan Pasterkamp <[email protected]>2022-09-17 12:55:00 +0200
commitc8b9567d1ba7f0ab20f93b60e5a8344c2c23c110 (patch)
treeab25f483d8ecd88e24e2e2d9f0c8726243816f3f /parse.go
parentebd7a68a06bef58b87c1fd21c2e7db383adbcbf3 (diff)
Feat: Add epilog after help text
Similar to the Description at the top of the help text an Epilog is added at the bottom. Resolves #189
Diffstat (limited to 'parse.go')
-rw-r--r--parse.go12
1 files changed, 12 insertions, 0 deletions
diff --git a/parse.go b/parse.go
index a883a10..c8cd79e 100644
--- a/parse.go
+++ b/parse.go
@@ -134,6 +134,7 @@ type Parser struct {
config Config
version string
description string
+ epilogue string
// the following field changes during processing of command line arguments
lastCmd *command
@@ -155,6 +156,14 @@ type Described interface {
Description() string
}
+// Epilogued is the interface that the destination struct should implement to
+// add an epilogue string at the bottom of the help message.
+type Epilogued interface {
+ // Epilogue returns the string that will be printed on a line by itself
+ // at the end of the help message.
+ Epilogue() string
+}
+
// walkFields calls a function for each field of a struct, recursively expanding struct fields.
func walkFields(t reflect.Type, visit func(field reflect.StructField, owner reflect.Type) bool) {
walkFieldsImpl(t, visit, nil)
@@ -236,6 +245,9 @@ func NewParser(config Config, dests ...interface{}) (*Parser, error) {
if dest, ok := dest.(Described); ok {
p.description = dest.Description()
}
+ if dest, ok := dest.(Epilogued); ok {
+ p.epilogue = dest.Epilogue()
+ }
}
return &p, nil