From c8b9567d1ba7f0ab20f93b60e5a8344c2c23c110 Mon Sep 17 00:00:00 2001 From: Sebastiaan Pasterkamp <26205277+SebastiaanPasterkamp@users.noreply.github.com> Date: Sat, 17 Sep 2022 12:39:31 +0200 Subject: 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 --- usage_test.go | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'usage_test.go') 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 { -- cgit v1.2.3