From 92130d91ba30fe142b9a1fa677444fbcaea7bdcf Mon Sep 17 00:00:00 2001 From: Mark Furland Date: Mon, 11 May 2020 14:08:55 -0400 Subject: [PATCH 01/10] Minimal manpage generation from cobra --- .gitignore | 2 ++ .goreleaser.yml | 4 ++++ Makefile | 8 ++++++++ cmd/gen-docs/main.go | 5 +++++ 4 files changed, 19 insertions(+) diff --git a/.gitignore b/.gitignore index 5ef399ba7..80891986e 100644 --- a/.gitignore +++ b/.gitignore @@ -16,3 +16,5 @@ .DS_Store vendor/ + +manpage diff --git a/.goreleaser.yml b/.goreleaser.yml index 8fca69fb3..4ceeee571 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -35,6 +35,8 @@ archives: replacements: darwin: macOS format: tar.gz + files: + - manpage/gh*.1 - id: windows builds: [windows] <<: *archive_defaults @@ -76,6 +78,8 @@ nfpms: formats: - deb - rpm + files: + "./manpage/gh*.1": "/usr/share/man/man1" scoop: bucket: diff --git a/Makefile b/Makefile index f2b4805c8..9dc9aae50 100644 --- a/Makefile +++ b/Makefile @@ -44,3 +44,11 @@ endif git -C site commit -m '$(GITHUB_REF:refs/tags/v%=%)' index.html git -C site push .PHONY: site-publish + + +manpage: + mkdir -p $@ + +.PHONY: manpages +manpages: manpage + go run ./cmd/gen-docs ./manpage diff --git a/cmd/gen-docs/main.go b/cmd/gen-docs/main.go index 6607054a9..82efa58f9 100644 --- a/cmd/gen-docs/main.go +++ b/cmd/gen-docs/main.go @@ -24,6 +24,11 @@ func main() { if err != nil { fatal(err) } + + err = doc.GenManTree(command.RootCmd, nil, dir) + if err != nil { + fatal(err) + } } func filePrepender(filename string) string { From e33706fbf49da6a2de1424775b9cc339858701b1 Mon Sep 17 00:00:00 2001 From: Mark Furland Date: Tue, 12 May 2020 09:51:25 -0400 Subject: [PATCH 02/10] Add flags for man vs website to cmd/gen-docs --- Makefile | 4 ++-- cmd/gen-docs/main.go | 48 ++++++++++++++++++++++++++++++++++---------- 2 files changed, 39 insertions(+), 13 deletions(-) diff --git a/Makefile b/Makefile index 9dc9aae50..87ec9d8d5 100644 --- a/Makefile +++ b/Makefile @@ -28,7 +28,7 @@ site: 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' @@ -51,4 +51,4 @@ manpage: .PHONY: manpages manpages: manpage - go run ./cmd/gen-docs ./manpage + go run ./cmd/gen-docs --man-page --doc-path ./manpage diff --git a/cmd/gen-docs/main.go b/cmd/gen-docs/main.go index 82efa58f9..9327da20a 100644 --- a/cmd/gen-docs/main.go +++ b/cmd/gen-docs/main.go @@ -7,27 +7,53 @@ 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 ") - } - dir := os.Args[1] - err := os.MkdirAll(dir, 0755) + var flagError pflag.ErrorHandling + docCmd := pflag.NewFlagSet("", flagError) + var manPage = docCmd.BoolP("man-page", "", false, "Generate manual pages") + var website = docCmd.BoolP("website", "", false, "Generate website pages") + var dir = docCmd.StringP("doc-path", "", "", "Path directory where you want generate doc files") + var 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) + } } - err = doc.GenManTree(command.RootCmd, nil, dir) - if err != nil { - fatal(err) + + if *manPage { + err = doc.GenManTree(command.RootCmd, nil, *dir) + if err != nil { + fatal(err) + } } } From 1cd6e3f9d3b1c460408867c689b74301d232076c Mon Sep 17 00:00:00 2001 From: Mark Furland Date: Tue, 12 May 2020 10:13:18 -0400 Subject: [PATCH 03/10] pass some options to GenManTree --- cmd/gen-docs/main.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/cmd/gen-docs/main.go b/cmd/gen-docs/main.go index 9327da20a..a878e339f 100644 --- a/cmd/gen-docs/main.go +++ b/cmd/gen-docs/main.go @@ -50,7 +50,13 @@ func main() { if *manPage { - err = doc.GenManTree(command.RootCmd, nil, *dir) + 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) } From e13fc2465f4af332021ebc81f399dc1f447784fe Mon Sep 17 00:00:00 2001 From: Mark Furland Date: Tue, 19 May 2020 12:21:17 -0400 Subject: [PATCH 04/10] use consistent var declaration format --- cmd/gen-docs/main.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cmd/gen-docs/main.go b/cmd/gen-docs/main.go index a878e339f..c7bb84afa 100644 --- a/cmd/gen-docs/main.go +++ b/cmd/gen-docs/main.go @@ -14,10 +14,10 @@ func main() { var flagError pflag.ErrorHandling docCmd := pflag.NewFlagSet("", flagError) - var manPage = docCmd.BoolP("man-page", "", false, "Generate manual pages") - var website = docCmd.BoolP("website", "", false, "Generate website pages") - var dir = docCmd.StringP("doc-path", "", "", "Path directory where you want generate doc files") - var help = docCmd.BoolP("help", "h", false, "Help about any command") + 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) From dffb55889c35fc5ff5d08af6ac67a15df2fd29d7 Mon Sep 17 00:00:00 2001 From: Mark Furland Date: Tue, 19 May 2020 15:58:27 -0400 Subject: [PATCH 05/10] install manpages for homebrew --- .goreleaser.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.goreleaser.yml b/.goreleaser.yml index 4ceeee571..be3dc2274 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -61,6 +61,7 @@ brews: install: | system "make" if build.head? bin.install "bin/gh" + man1.install Dir["manpages/*.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` From db2fac93ea88a6a7801185e828a63d3bb4aa8c6b Mon Sep 17 00:00:00 2001 From: Mark Furland Date: Tue, 19 May 2020 18:43:26 -0400 Subject: [PATCH 06/10] generate manpages into ./share/man/man1 --- .gitignore | 3 +-- .goreleaser.yml | 6 +++--- Makefile | 4 ++-- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index 80891986e..00a5bb5a6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ /bin +/share/man/man1 /gh-cli .envrc /dist @@ -16,5 +17,3 @@ .DS_Store vendor/ - -manpage diff --git a/.goreleaser.yml b/.goreleaser.yml index be3dc2274..0996d24d5 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -36,7 +36,7 @@ archives: darwin: macOS format: tar.gz files: - - manpage/gh*.1 + - ./share/man/man1/gh*.1 - id: windows builds: [windows] <<: *archive_defaults @@ -61,7 +61,7 @@ brews: install: | system "make" if build.head? bin.install "bin/gh" - man1.install Dir["manpages/*.1"] + 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` @@ -80,7 +80,7 @@ nfpms: - deb - rpm files: - "./manpage/gh*.1": "/usr/share/man/man1" + "./share/man/man1/gh*.1": "/usr/share/man/man1" scoop: bucket: diff --git a/Makefile b/Makefile index 87ec9d8d5..bcf564947 100644 --- a/Makefile +++ b/Makefile @@ -46,9 +46,9 @@ endif .PHONY: site-publish -manpage: +share/man/man1/: mkdir -p $@ .PHONY: manpages manpages: manpage - go run ./cmd/gen-docs --man-page --doc-path ./manpage + go run ./cmd/gen-docs --man-page --doc-path ./share/man/man1/ From 6387078532c2596a4c5615e079df82144801f928 Mon Sep 17 00:00:00 2001 From: Mark Furland Date: Tue, 19 May 2020 22:40:14 -0400 Subject: [PATCH 07/10] add make manpages hook and fix makefile --- .goreleaser.yml | 4 ++++ Makefile | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/.goreleaser.yml b/.goreleaser.yml index 0996d24d5..a37a5c0e7 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -17,10 +17,14 @@ builds: id: macos goos: [darwin] goarch: [amd64] + hooks: + pre: make manpages + - <<: *build_defaults id: linux goos: [linux] goarch: [386, amd64, arm64] + - <<: *build_defaults id: windows goos: [windows] diff --git a/Makefile b/Makefile index bcf564947..c284f6c57 100644 --- a/Makefile +++ b/Makefile @@ -46,9 +46,9 @@ endif .PHONY: site-publish -share/man/man1/: +share/man/man1: mkdir -p $@ .PHONY: manpages -manpages: manpage +manpages: share/man/man1 go run ./cmd/gen-docs --man-page --doc-path ./share/man/man1/ From af93bab887cde7cafd3ad9d6d94e9c6c301c6af0 Mon Sep 17 00:00:00 2001 From: Mark Furland Date: Tue, 19 May 2020 22:42:44 -0400 Subject: [PATCH 08/10] remove unnecessary mkdir from makefile --- Makefile | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/Makefile b/Makefile index c284f6c57..dd863cb0d 100644 --- a/Makefile +++ b/Makefile @@ -46,9 +46,6 @@ endif .PHONY: site-publish -share/man/man1: - mkdir -p $@ - .PHONY: manpages -manpages: share/man/man1 +manpages: go run ./cmd/gen-docs --man-page --doc-path ./share/man/man1/ From a9e83dcc36caefbcee47a9048893ce90437db1eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Wed, 20 May 2020 13:07:48 +0200 Subject: [PATCH 09/10] Tweak release process re: man pages --- .goreleaser.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.goreleaser.yml b/.goreleaser.yml index a37a5c0e7..6240b028f 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -6,6 +6,7 @@ release: before: hooks: - go mod tidy + - make manpages builds: - <<: &build_defaults @@ -17,8 +18,6 @@ builds: id: macos goos: [darwin] goarch: [amd64] - hooks: - pre: make manpages - <<: *build_defaults id: linux @@ -63,7 +62,7 @@ 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` From 6385c32031874d8f2c968c9d05e873b167af0ca3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Wed, 20 May 2020 13:15:44 +0200 Subject: [PATCH 10/10] Include license information in release archives --- .goreleaser.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.goreleaser.yml b/.goreleaser.yml index 6240b028f..ceb22c12e 100644 --- a/.goreleaser.yml +++ b/.goreleaser.yml @@ -39,12 +39,15 @@ archives: 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