Merge pull request #915 from mtfurlan/docs/manpage

Generate manpages from cobra
This commit is contained in:
Nate Smith 2020-05-20 09:58:50 -05:00 committed by GitHub
commit e9d6e13339
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 64 additions and 10 deletions

1
.gitignore vendored
View file

@ -1,4 +1,5 @@
/bin
/share/man/man1
/gh-cli
.envrc
/dist

View file

@ -6,6 +6,7 @@ release:
before:
hooks:
- go mod tidy
- make manpages
builds:
- <<: &build_defaults
@ -17,10 +18,12 @@ builds:
id: macos
goos: [darwin]
goarch: [amd64]
- <<: *build_defaults
id: linux
goos: [linux]
goarch: [386, amd64, arm64]
- <<: *build_defaults
id: windows
goos: [windows]
@ -35,11 +38,16 @@ archives:
replacements:
darwin: macOS
format: tar.gz
files:
- LICENSE
- ./share/man/man1/gh*.1
- id: windows
builds: [windows]
<<: *archive_defaults
wrap_in_directory: false
format: zip
files:
- LICENSE
brews:
- name: gh
@ -57,8 +65,9 @@ brews:
depends_on "go"
end
install: |
system "make" if build.head?
system "make", "bin/gh", "manpages" if build.head?
bin.install "bin/gh"
man1.install Dir["./share/man/man1/gh*.1"]
(bash_completion/"gh.sh").write `#{bin}/gh completion -s bash`
(zsh_completion/"_gh").write `#{bin}/gh completion -s zsh`
(fish_completion/"gh.fish").write `#{bin}/gh completion -s fish`
@ -76,6 +85,8 @@ nfpms:
formats:
- deb
- rpm
files:
"./share/man/man1/gh*.1": "/usr/share/man/man1"
scoop:
bucket:

View file

@ -28,7 +28,7 @@ site: bin/gh
site-docs: site
git -C site pull
git -C site rm 'manual/gh*.md' 2>/dev/null || true
go run ./cmd/gen-docs site/manual
go run ./cmd/gen-docs --website --doc-path site/manual
for f in site/manual/gh*.md; do sed -i.bak -e '/^### SEE ALSO/,$$d' "$$f"; done
rm -f site/manual/*.bak
git -C site add 'manual/gh*.md'
@ -44,3 +44,8 @@ endif
git -C site commit -m '$(GITHUB_REF:refs/tags/v%=%)' index.html
git -C site push
.PHONY: site-publish
.PHONY: manpages
manpages:
go run ./cmd/gen-docs --man-page --doc-path ./share/man/man1/

View file

@ -7,22 +7,59 @@ import (
"github.com/cli/cli/command"
"github.com/spf13/cobra/doc"
"github.com/spf13/pflag"
)
func main() {
if len(os.Args) < 2 {
fatal("Usage: gen-docs <destination-dir>")
}
dir := os.Args[1]
err := os.MkdirAll(dir, 0755)
var flagError pflag.ErrorHandling
docCmd := pflag.NewFlagSet("", flagError)
manPage := docCmd.BoolP("man-page", "", false, "Generate manual pages")
website := docCmd.BoolP("website", "", false, "Generate website pages")
dir := docCmd.StringP("doc-path", "", "", "Path directory where you want generate doc files")
help := docCmd.BoolP("help", "h", false, "Help about any command")
if err := docCmd.Parse(os.Args); err != nil {
os.Exit(1)
}
if *help {
_, err := fmt.Fprintf(os.Stderr, "Usage of %s:\n\n%s", os.Args[0], docCmd.FlagUsages())
if err != nil {
fatal(err)
}
os.Exit(1)
}
if(*dir == "") {
fatal("no dir set")
}
err := os.MkdirAll(*dir, 0755)
if err != nil {
fatal(err)
}
err = doc.GenMarkdownTreeCustom(command.RootCmd, dir, filePrepender, linkHandler)
if err != nil {
fatal(err)
if *website {
err = doc.GenMarkdownTreeCustom(command.RootCmd, *dir, filePrepender, linkHandler)
if err != nil {
fatal(err)
}
}
if *manPage {
header := &doc.GenManHeader{
Title: "gh",
Section: "1",
Source: "", //source and manual are just put at the top of the manpage, before name
Manual: "", //if source is an empty string, it's set to "Auto generated by spf13/cobra"
}
err = doc.GenManTree(command.RootCmd, header, *dir)
if err != nil {
fatal(err)
}
}
}