Skip to content

Commit

Permalink
feat: generate man pages (#443)
Browse files Browse the repository at this point in the history
* feat: migrate to coral

Signed-off-by: Carlos A Becker <caarlos0@gmail.com>

* feat: generate man pages

Signed-off-by: Carlos A Becker <caarlos0@gmail.com>
  • Loading branch information
caarlos0 committed Feb 3, 2022
1 parent 596412c commit 13e7667
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ testdata/acceptance/tmp/
completions/
.task/
cosign.*
manpages
5 changes: 5 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ before:
hooks:
- go mod tidy
- ./scripts/completions.sh
- ./scripts/manpages.sh

gomod:
proxy: true
Expand Down Expand Up @@ -87,6 +88,7 @@ archives:
- README.md
- LICENSE.md
- completions/*
- manpages/*

brews:
- tap:
Expand All @@ -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:
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
38 changes: 38 additions & 0 deletions internal/cmd/man.go
Original file line number Diff line number Diff line change
@@ -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
}
1 change: 1 addition & 0 deletions internal/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ func newRootCmd(version string, exit func(int)) *rootCmd {
newInitCmd().cmd,
newPackageCmd().cmd,
newDocsCmd().cmd,
newManCmd().cmd,
newSchemaCmd().cmd,
)

Expand Down
5 changes: 5 additions & 0 deletions scripts/manpages.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/sh
set -e
rm -rf manpages
mkdir manpages
go run ./cmd/nfpm/ man | gzip -c >manpages/nfpm.1.gz

0 comments on commit 13e7667

Please sign in to comment.