aboutsummaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
authorChristine Dodrill <me@christine.website>2018-12-09 08:52:03 -0800
committerChristine Dodrill <me@christine.website>2018-12-09 08:52:30 -0800
commit223095c3f5da5ae63cddcecdfc16f0371afa9939 (patch)
tree985330b212a8c1b7450d773f3f9a5a1d7f5064d8 /internal
parentd66cd9cd7505c19b76379fe18ca7dbae1ff2a4a8 (diff)
downloadx-223095c3f5da5ae63cddcecdfc16f0371afa9939.tar.xz
x-223095c3f5da5ae63cddcecdfc16f0371afa9939.zip
start on manpages
Diffstat (limited to 'internal')
-rw-r--r--internal/manpage/gen.go102
1 files changed, 102 insertions, 0 deletions
diff --git a/internal/manpage/gen.go b/internal/manpage/gen.go
new file mode 100644
index 0000000..94a3ccf
--- /dev/null
+++ b/internal/manpage/gen.go
@@ -0,0 +1,102 @@
+package manpage
+
+import (
+ "flag"
+ "html/template"
+ "log"
+ "os"
+ "path/filepath"
+ "strings"
+ "time"
+)
+
+// DateFormat is the date format used in manpages.
+const DateFormat = "January 02, 2006"
+
+// Spew spews out a manpage template for this program then stops execution.
+func Spew() {
+ var result struct {
+ Flags []*flag.Flag
+ Name string
+ UName string
+ Date string
+ }
+
+ result.Name = filepath.Base(os.Args[0])
+ result.UName = strings.ToUpper(result.Name)
+ result.Date = time.Now().Format(DateFormat)
+
+ flag.VisitAll(func(f *flag.Flag) {
+ result.Flags = append(result.Flags, f)
+ })
+
+ var err error
+ t := template.New("manpage.1")
+ t, err = t.Parse(manpageTemplate)
+ if err != nil {
+ log.Fatal(err)
+ }
+
+ err = t.Execute(os.Stdout, result)
+ if err != nil {
+ log.Fatal(err)
+ }
+
+ os.Exit(0)
+}
+
+const manpageTemplate = `.Dd {{.Date}}
+.Dt {{ .UName }} 1 URM
+
+
+.Sh NAME
+.Nm {{ .Name }}
+.Nd This is a command that needs a description.
+
+
+.Sh SYNOPSIS
+.Nm
+{{ range .Flags }}
+.Op Fl {{ .Name }}
+{{ end }}
+
+
+.Sh DESCRIPTION
+.Nm
+is
+
+TODO: FIXME
+
+.Bl -tag -width " " -offset indent -compact
+
+{{ range .Flags }}
+.It Fl {{ .Name }}
+{{ .Usage }}
+
+The default value for this is {{ .DefValue }}
+{{ end }}
+
+.El
+
+
+.Sh EXAMPLES
+
+.Li {{ .Name }}
+
+.Li {{ .Name }} -license
+
+
+.Sh DIAGNOSTICS
+
+.Ex -std {{ .Name }}
+
+
+.Sh SEE ALSO
+
+.Bl -bullet
+
+.It
+.Lk hyperlink: http://some.domain Some Text
+
+.El
+`