From 13e76671c005e1da6d689ffb5e5e0d118c546f85 Mon Sep 17 00:00:00 2001 From: Carlos Alexandro Becker Date: Wed, 2 Feb 2022 23:30:46 -0300 Subject: [PATCH] feat: generate man pages (#443) * feat: migrate to coral Signed-off-by: Carlos A Becker * feat: generate man pages Signed-off-by: Carlos A Becker --- .gitignore | 1 + .goreleaser.yml | 5 +++++ go.mod | 4 ++++ go.sum | 8 ++++++++ internal/cmd/man.go | 38 ++++++++++++++++++++++++++++++++++++++ internal/cmd/root.go | 1 + scripts/manpages.sh | 5 +++++ 7 files changed, 62 insertions(+) create mode 100644 internal/cmd/man.go create mode 100755 scripts/manpages.sh diff --git a/.gitignore b/.gitignore index 4ce9e23..0cb34d8 100644 --- a/.gitignore +++ b/.gitignore @@ -16,3 +16,4 @@ testdata/acceptance/tmp/ completions/ .task/ cosign.* +manpages diff --git a/.goreleaser.yml b/.goreleaser.yml index 810717f..eace038 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -5,6 +5,7 @@ before: hooks: - go mod tidy - ./scripts/completions.sh + - ./scripts/manpages.sh gomod: proxy: true @@ -87,6 +88,7 @@ archives: - README.md - LICENSE.md - completions/* + - manpages/* brews: - tap: @@ -103,6 +105,7 @@ brews: bash_completion.install "completions/nfpm.bash" => "nfpm" zsh_completion.install "completions/nfpm.zsh" => "_nfpm" fish_completion.install "completions/nfpm.fish" + man1.install "manpages/nfpm.1.gz" rigs: - rig: @@ -138,6 +141,8 @@ nfpms: dst: /usr/share/fish/completions/nfpm.fish - src: ./completions/nfpm.zsh dst: /usr/local/share/zsh/site-functions/_nfpm + - src: ./manpages/nfpm.1.gz + dst: /usr/share/man/man1/nfpm.1.gz furies: - account: goreleaser diff --git a/go.mod b/go.mod index 97ab54c..7ea14b5 100644 --- a/go.mod +++ b/go.mod @@ -15,6 +15,8 @@ require ( github.com/goreleaser/fileglob v1.2.0 github.com/imdario/mergo v0.3.12 github.com/muesli/coral v1.0.0 + github.com/muesli/mango-coral v1.0.0 + github.com/muesli/roff v0.1.0 github.com/stretchr/testify v1.7.0 github.com/ulikunitz/xz v0.5.10 github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8 @@ -48,6 +50,8 @@ require ( github.com/mitchellh/copystructure v1.2.0 // indirect github.com/mitchellh/go-homedir v1.1.0 // indirect github.com/mitchellh/reflectwalk v1.0.2 // indirect + github.com/muesli/mango v0.0.0-20220201014152-f7df5a1c5b4b // indirect + github.com/muesli/mango-pflag v0.0.0-20220201014449-d694870c5590 // indirect github.com/pkg/errors v0.9.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/russross/blackfriday/v2 v2.1.0 // indirect diff --git a/go.sum b/go.sum index 437513f..8223a98 100644 --- a/go.sum +++ b/go.sum @@ -235,6 +235,14 @@ github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJ github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= github.com/muesli/coral v1.0.0 h1:odyqkoEg4aJAINOzvnjN4tUsdp+Zleccs7tRIAkkYzU= github.com/muesli/coral v1.0.0/go.mod h1:bf91M/dkp7iHQw73HOoR9PekdTJMTD6ihJgWoDitde8= +github.com/muesli/mango v0.0.0-20220201014152-f7df5a1c5b4b h1:kGcKjlZqUNbpUjBMdIq5/RbA2gN9ypH0Tv+MNBtCgK4= +github.com/muesli/mango v0.0.0-20220201014152-f7df5a1c5b4b/go.mod h1:5XFpbC8jY5UUv89YQciiXNlbi+iJgt29VDC5xbzrLL4= +github.com/muesli/mango-coral v1.0.0 h1:OnUtvcHZ+Q2yi0B6RXm2VJVnOJVvY7G947t4ybUy868= +github.com/muesli/mango-coral v1.0.0/go.mod h1:8sxkm+gsWOnUiv5gpvtilx4OErv1nQVSJXJmNkExxBs= +github.com/muesli/mango-pflag v0.0.0-20220201014449-d694870c5590 h1:bZgkcUsck7Y6kMUcpettBv6jUck4rTrgPEBIKwFbGpM= +github.com/muesli/mango-pflag v0.0.0-20220201014449-d694870c5590/go.mod h1:o2wTF9T2N5YEx+lHxQ6R3RsUg9NH4jyaOIlnJN5KQ04= +github.com/muesli/roff v0.1.0 h1:YD0lalCotmYuF5HhZliKWlIx7IEhiXeSfq7hNjFqGF8= +github.com/muesli/roff v0.1.0/go.mod h1:pjAHQM9hdUUwm/krAfrLGgJkXJ+YuhtsfZ42kieB2Ig= github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U= diff --git a/internal/cmd/man.go b/internal/cmd/man.go new file mode 100644 index 0000000..1967bed --- /dev/null +++ b/internal/cmd/man.go @@ -0,0 +1,38 @@ +package cmd + +import ( + "fmt" + "os" + + "github.com/muesli/coral" + mcoral "github.com/muesli/mango-coral" + "github.com/muesli/roff" +) + +type manCmd struct { + cmd *coral.Command +} + +func newManCmd() *manCmd { + root := &manCmd{} + cmd := &coral.Command{ + Use: "man", + Short: "Generates nfpm's command line manpages", + SilenceUsage: true, + DisableFlagsInUseLine: true, + Hidden: true, + Args: coral.NoArgs, + RunE: func(cmd *coral.Command, args []string) error { + manPage, err := mcoral.NewManPage(1, root.cmd.Root()) + if err != nil { + return err + } + + _, err = fmt.Fprint(os.Stdout, manPage.Build(roff.NewDocument())) + return err + }, + } + + root.cmd = cmd + return root +} diff --git a/internal/cmd/root.go b/internal/cmd/root.go index ef330e9..36b6aca 100644 --- a/internal/cmd/root.go +++ b/internal/cmd/root.go @@ -45,6 +45,7 @@ func newRootCmd(version string, exit func(int)) *rootCmd { newInitCmd().cmd, newPackageCmd().cmd, newDocsCmd().cmd, + newManCmd().cmd, newSchemaCmd().cmd, ) diff --git a/scripts/manpages.sh b/scripts/manpages.sh new file mode 100755 index 0000000..c5affd1 --- /dev/null +++ b/scripts/manpages.sh @@ -0,0 +1,5 @@ +#!/bin/sh +set -e +rm -rf manpages +mkdir manpages +go run ./cmd/nfpm/ man | gzip -c >manpages/nfpm.1.gz