From f66f6cfc21328de574e996f473a16a0762d1f557 Mon Sep 17 00:00:00 2001 From: Gabe Cook Date: Mon, 11 Mar 2024 23:37:48 -0500 Subject: [PATCH] docs: Add generated usage docs --- .pre-commit-config.yaml | 8 ++++++++ cmd/cmd.go | 2 ++ docs/changelog-generator.md | 15 +++++++++++++++ go.mod | 2 ++ go.sum | 2 ++ internal/generate/docs/main.go | 32 ++++++++++++++++++++++++++++++++ 6 files changed, 61 insertions(+) create mode 100644 docs/changelog-generator.md create mode 100644 internal/generate/docs/main.go diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 42a0e7e..2dfc0ef 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -8,3 +8,11 @@ repos: - id: go-vet-mod - id: golangci-lint-mod args: [--fix] + + - repo: local + hooks: + - id: usage-docs + name: usage-docs + entry: go run ./internal/generate/docs + language: system + pass_filenames: false diff --git a/cmd/cmd.go b/cmd/cmd.go index 022de11..770026e 100644 --- a/cmd/cmd.go +++ b/cmd/cmd.go @@ -15,6 +15,8 @@ func New() *cobra.Command { cmd := &cobra.Command{ Use: "changelog-generator", RunE: run, + + DisableAutoGenTag: true, } cmd.PersistentFlags().String("config", "", `Config file (default ".changelog-generator.yaml")`) diff --git a/docs/changelog-generator.md b/docs/changelog-generator.md new file mode 100644 index 0000000..f0ce1f9 --- /dev/null +++ b/docs/changelog-generator.md @@ -0,0 +1,15 @@ +## changelog-generator + + + +``` +changelog-generator [flags] +``` + +### Options + +``` + --config string Config file (default ".changelog-generator.yaml") + -h, --help help for changelog-generator +``` + diff --git a/go.mod b/go.mod index d3ccbb8..e239d3f 100644 --- a/go.mod +++ b/go.mod @@ -16,6 +16,7 @@ require ( github.com/Microsoft/go-winio v0.6.1 // indirect github.com/ProtonMail/go-crypto v1.0.0 // indirect github.com/cloudflare/circl v1.3.7 // indirect + github.com/cpuguy83/go-md2man/v2 v2.0.3 // indirect github.com/cyphar/filepath-securejoin v0.2.4 // indirect github.com/emirpasic/gods v1.18.1 // indirect github.com/fatih/structs v1.1.0 // indirect @@ -31,6 +32,7 @@ require ( github.com/mitchellh/copystructure v1.2.0 // indirect github.com/mitchellh/reflectwalk v1.0.2 // indirect github.com/pjbgf/sha1cd v0.3.0 // indirect + github.com/russross/blackfriday/v2 v2.1.0 // indirect github.com/sergi/go-diff v1.3.1 // indirect github.com/skeema/knownhosts v1.2.1 // indirect github.com/spf13/pflag v1.0.5 // indirect diff --git a/go.sum b/go.sum index c4ee21d..728dc68 100644 --- a/go.sum +++ b/go.sum @@ -13,6 +13,7 @@ github.com/bwesterb/go-ristretto v1.2.3/go.mod h1:fUIoIZaG73pV5biE2Blr2xEzDoMj7N github.com/cloudflare/circl v1.3.3/go.mod h1:5XYMA4rFBvNIrhs50XuiBJ15vF2pZn4nnUKZrLbUZFA= github.com/cloudflare/circl v1.3.7 h1:qlCDlTPz2n9fu58M0Nh1J/JzcFpfgkFHHX3O35r5vcU= github.com/cloudflare/circl v1.3.7/go.mod h1:sRTcRWXGLrKw6yIGJ+l7amYJFfAXbZG0kBSc8r4zxgA= +github.com/cpuguy83/go-md2man/v2 v2.0.3 h1:qMCsGGgs+MAzDFyp9LpAe1Lqy/fY/qCovCm0qnXZOBM= github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/cyphar/filepath-securejoin v0.2.4 h1:Ugdm7cg7i6ZK6x3xDF1oEu1nfkyfH53EtKeQYTC3kyg= github.com/cyphar/filepath-securejoin v0.2.4/go.mod h1:aPGpWjXOXUn2NCNjFvBE6aRxGGx79pTxQpKOJNYHHl4= @@ -80,6 +81,7 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M= github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA= +github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk= github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= github.com/sergi/go-diff v1.3.1 h1:xkr+Oxo4BOQKmkn/B9eMK0g5Kg/983T9DqqPHwYqD+8= github.com/sergi/go-diff v1.3.1/go.mod h1:aMJSSKb2lpPvRNec0+w3fl7LP9IOFzdc9Pa4NFbPK1I= diff --git a/internal/generate/docs/main.go b/internal/generate/docs/main.go new file mode 100644 index 0000000..7e9ac20 --- /dev/null +++ b/internal/generate/docs/main.go @@ -0,0 +1,32 @@ +package main + +import ( + "fmt" + "log" + "os" + + "github.com/gabe565/changelog-generator/cmd" + "github.com/spf13/cobra/doc" +) + +func main() { + var err error + output := "./docs" + + err = os.RemoveAll(output) + if err != nil { + log.Fatal(fmt.Errorf("failed to remove existing dia: %w", err)) + } + + err = os.MkdirAll(output, 0o755) + if err != nil { + log.Fatal(fmt.Errorf("failed to mkdir: %w", err)) + } + + rootCmd := cmd.New() + + err = doc.GenMarkdownTree(rootCmd, output) + if err != nil { + log.Fatal(fmt.Errorf("failed to generate markdown: %w", err)) + } +}