Generate man page when built with 'mango' build-tag

Christian Muehlhaeuser created

When building with the 'mango' build-tag (go build -tags mango) enabled,
we will simply generate and print a man-page on startup and immediately
exit again.

Change summary

cmd/soft/man.go | 25 +++++++++++++++++++++++++
go.mod          |  5 +++++
go.sum          |  4 ++++
3 files changed, 34 insertions(+)

Detailed changes

cmd/soft/man.go 🔗

@@ -0,0 +1,25 @@
+//go:build mango
+// +build mango
+
+package main
+
+import (
+	"flag"
+	"fmt"
+	"os"
+
+	"github.com/muesli/mango"
+	"github.com/muesli/mango/mflag"
+	"github.com/muesli/roff"
+)
+
+func init() {
+	manPage := mango.NewManPage(1, "soft", "A self-hostable Git server for the command line").
+		WithLongDescription("Soft Serve is a self-hostable Git server for the command line.").
+		WithSection("Copyright", "(C) 2021-2022 Charmbracelet, Inc.\n"+
+			"Released under MIT license.")
+
+	flag.VisitAll(mflag.FlagVisitor(manPage))
+	fmt.Println(manPage.Build(roff.NewDocument()))
+	os.Exit(0)
+}

go.mod 🔗

@@ -22,6 +22,11 @@ require (
 	gopkg.in/yaml.v2 v2.4.0
 )
 
+require (
+	github.com/muesli/mango v0.1.0
+	github.com/muesli/roff v0.1.0
+)
+
 require (
 	github.com/Microsoft/go-winio v0.5.1 // indirect
 	github.com/ProtonMail/go-crypto v0.0.0-20220113124808-70ae35bab23f // indirect

go.sum 🔗

@@ -104,9 +104,13 @@ github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrk
 github.com/muesli/ansi v0.0.0-20211018074035-2e021307bc4b/go.mod h1:fQuZ0gauxyBcmsdE3ZT4NasjaRdxmbCS0jRHsrWu3Ho=
 github.com/muesli/ansi v0.0.0-20211031195517-c9f0611b6c70 h1:kMlmsLSbjkikxQJ1IPwaM+7LJ9ltFu/fi8CRzvSnQmA=
 github.com/muesli/ansi v0.0.0-20211031195517-c9f0611b6c70/go.mod h1:fQuZ0gauxyBcmsdE3ZT4NasjaRdxmbCS0jRHsrWu3Ho=
+github.com/muesli/mango v0.1.0 h1:DZQK45d2gGbql1arsYA4vfg4d7I9Hfx5rX/GCmzsAvI=
+github.com/muesli/mango v0.1.0/go.mod h1:5XFpbC8jY5UUv89YQciiXNlbi+iJgt29VDC5xbzrLL4=
 github.com/muesli/reflow v0.2.1-0.20210115123740-9e1d0d53df68/go.mod h1:Xk+z4oIWdQqJzsxyjgl3P22oYZnHdZ8FFTHAQQt5BMQ=
 github.com/muesli/reflow v0.3.0 h1:IFsN6K9NfGtjeggFP+68I4chLZV2yIKsXJFNZ+eWh6s=
 github.com/muesli/reflow v0.3.0/go.mod h1:pbwTDkVPibjO2kyvBQRBxTWEEGDGq0FlB1BIKtnHY/8=
+github.com/muesli/roff v0.1.0 h1:YD0lalCotmYuF5HhZliKWlIx7IEhiXeSfq7hNjFqGF8=
+github.com/muesli/roff v0.1.0/go.mod h1:pjAHQM9hdUUwm/krAfrLGgJkXJ+YuhtsfZ42kieB2Ig=
 github.com/muesli/termenv v0.9.0/go.mod h1:R/LzAKf+suGs4IsO95y7+7DpFHO0KABgnZqtlyx2mBw=
 github.com/muesli/termenv v0.11.0 h1:fwNUbu2mfWlgicwG7qYzs06aOI8Z/zKPAv8J4uKbT+o=
 github.com/muesli/termenv v0.11.0/go.mod h1:Bd5NYQ7pd+SrtBSrSNoBBmXlcY8+Xj4BMJgh8qcZrvs=