Skip to content

Commit

Permalink
feat: manpages (#2837)
Browse files Browse the repository at this point in the history
* feat: manpages

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

* fix: section

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

* feat: use mango instead

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

* fix: improvements

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

* fix: unused

Signed-off-by: Carlos A Becker <caarlos0@gmail.com>
  • Loading branch information
caarlos0 committed Jan 18, 2022
1 parent 87151f8 commit ae58345
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -12,3 +12,4 @@ completions/
.vscode/
.task/
.idea/
manpages
4 changes: 4 additions & 0 deletions .goreleaser.yaml
Expand Up @@ -5,6 +5,7 @@ before:
hooks:
- go mod tidy
- ./scripts/completions.sh
- ./scripts/manpages.sh

snapshot:
name_template: '{{ incpatch .Version }}-next'
Expand Down Expand Up @@ -149,6 +150,7 @@ brews:
bash_completion.install "completions/goreleaser.bash" => "goreleaser"
zsh_completion.install "completions/goreleaser.zsh" => "_goreleaser"
fish_completion.install "completions/goreleaser.fish"
man1.install "manpages/goreleaser.1.gz"
rigs:
- rig:
Expand Down Expand Up @@ -181,6 +183,8 @@ nfpms:
dst: /usr/share/fish/completions/goreleaser.fish
- src: ./completions/goreleaser.zsh
dst: /usr/local/share/zsh/site-functions/_goreleaser
- src: ./manpages/goreleaser.1.gz
dst: /usr/share/man/man1/goreleaser.1.gz
formats:
- apk
- deb
Expand Down
38 changes: 38 additions & 0 deletions cmd/man.go
@@ -0,0 +1,38 @@
package cmd

import (
"fmt"
"os"

"github.com/muesli/mango/mcobra"
"github.com/muesli/roff"
"github.com/spf13/cobra"
)

type manCmd struct {
cmd *cobra.Command
}

func newManCmd() *manCmd {
root := &manCmd{}
cmd := &cobra.Command{
Use: "man",
Short: "Generates GoReleaser's command line manpages",
SilenceUsage: true,
DisableFlagsInUseLine: true,
Hidden: true,
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
manPage, err := mcobra.NewManPageFromCobra(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 cmd/root.go
Expand Up @@ -83,6 +83,7 @@ single .goreleaser.yaml file.
newCheckCmd().cmd,
newInitCmd().cmd,
newDocsCmd().cmd,
newManCmd().cmd,
newSchemaCmd().cmd,
)

Expand Down
2 changes: 2 additions & 0 deletions go.mod
Expand Up @@ -24,6 +24,8 @@ require (
github.com/imdario/mergo v0.3.12
github.com/jarcoal/httpmock v1.1.0
github.com/mitchellh/go-homedir v1.1.0
github.com/muesli/mango v0.0.0-20220118122812-f367188b892e
github.com/muesli/roff v0.1.0
github.com/slack-go/slack v0.10.1
github.com/spf13/cobra v1.3.0
github.com/stretchr/testify v1.7.0
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Expand Up @@ -664,6 +664,10 @@ github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJ
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
github.com/muesli/mango v0.0.0-20220118122812-f367188b892e h1:ykZ/Hqqvqm2lmZ1YoruxTWaOb90IKlkMuT0Io9baO+A=
github.com/muesli/mango v0.0.0-20220118122812-f367188b892e/go.mod h1:r40g5Hx6ZzbjDW0GZhCpSX2Wyt9SPSDRoQGaODqxSz4=
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
5 changes: 5 additions & 0 deletions scripts/manpages.sh
@@ -0,0 +1,5 @@
#!/bin/sh
set -e
rm -rf manpages
mkdir manpages
go run . man | gzip -c >manpages/goreleaser.1.gz

0 comments on commit ae58345

Please sign in to comment.