summaryrefslogtreecommitdiff
path: root/usage_test.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 /usage_test.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 'usage_test.go')
-rw-r--r--usage_test.go31
1 files changed, 31 insertions, 0 deletions
diff --git a/usage_test.go b/usage_test.go
index 1744536..fd67fc8 100644
--- a/usage_test.go
+++ b/usage_test.go
@@ -285,6 +285,37 @@ Options:
assert.Equal(t, expectedUsage, strings.TrimSpace(usage.String()))
}
+type epilogued struct{}
+
+// Epilogued returns the epilogue for this program
+func (epilogued) Epilogue() string {
+ return "For more information visit github.com/alexflint/go-arg"
+}
+
+func TestUsageWithEpilogue(t *testing.T) {
+ expectedUsage := "Usage: example"
+
+ expectedHelp := `
+Usage: example
+
+Options:
+ --help, -h display this help and exit
+
+For more information visit github.com/alexflint/go-arg
+`
+ os.Args[0] = "example"
+ p, err := NewParser(Config{}, &epilogued{})
+ require.NoError(t, err)
+
+ var help bytes.Buffer
+ p.WriteHelp(&help)
+ assert.Equal(t, expectedHelp[1:], help.String())
+
+ var usage bytes.Buffer
+ p.WriteUsage(&usage)
+ assert.Equal(t, expectedUsage, strings.TrimSpace(usage.String()))
+}
+
func TestUsageForRequiredPositionals(t *testing.T) {
expectedUsage := "Usage: example REQUIRED1 REQUIRED2\n"
var args struct {