From 644155567c915fa9fd07e1d7f1bc8e933e5805a3 Mon Sep 17 00:00:00 2001 From: Gabe Cook Date: Fri, 12 Jul 2024 16:57:44 -0500 Subject: [PATCH] docs: Add generated docs --- .pre-commit-config.yaml | 8 ++++++++ cmd/cmd.go | 8 +++++--- docs/cli-of-life.md | 17 +++++++++++++++++ go.mod | 2 ++ go.sum | 2 ++ internal/generate/docs/main.go | 21 +++++++++++++++++++++ 6 files changed, 55 insertions(+), 3 deletions(-) create mode 100644 docs/cli-of-life.md create mode 100644 internal/generate/docs/main.go diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 70fecf5..e2b18cc 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -5,3 +5,11 @@ repos: - id: go-mod-tidy-repo - id: golangci-lint-mod args: [--fix] + + - repo: local + hooks: + - id: usage-docs + name: usage-docs + entry: go run -tags rand_insecure_for_docs ./internal/generate/docs + language: system + pass_filenames: false diff --git a/cmd/cmd.go b/cmd/cmd.go index 1d2dae0..d8515e7 100644 --- a/cmd/cmd.go +++ b/cmd/cmd.go @@ -13,11 +13,13 @@ import ( func New() *cobra.Command { cmd := &cobra.Command{ - Use: "cli-of-life", - RunE: run, - Args: cobra.NoArgs, + Use: "cli-of-life", + Short: "Play Conway's Game of Life in your terminal", + RunE: run, + Args: cobra.NoArgs, ValidArgsFunction: cobra.NoFileCompletions, + DisableAutoGenTag: true, } cmd.Flags().StringP(config.FileFlag, "f", "", "Loads a pattern file on startup") diff --git a/docs/cli-of-life.md b/docs/cli-of-life.md new file mode 100644 index 0000000..d49281d --- /dev/null +++ b/docs/cli-of-life.md @@ -0,0 +1,17 @@ +## cli-of-life + +Play Conway's Game of Life in your terminal + +``` +cli-of-life [flags] +``` + +### Options + +``` + --completion string Output command-line completion code for the specified shell. Can be 'bash', 'zsh', 'fish', or 'powershell'. + -f, --file string Loads a pattern file on startup + --file-format string File format (one of: auto, rle, plaintext) (default "auto") + -h, --help help for cli-of-life +``` + diff --git a/go.mod b/go.mod index 46878aa..f1bb330 100644 --- a/go.mod +++ b/go.mod @@ -16,6 +16,7 @@ require ( github.com/charmbracelet/x/input v0.1.0 // indirect github.com/charmbracelet/x/term v0.1.1 // indirect github.com/charmbracelet/x/windows v0.1.0 // indirect + github.com/cpuguy83/go-md2man/v2 v2.0.4 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect @@ -29,6 +30,7 @@ require ( github.com/muesli/termenv v0.15.2 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect github.com/rivo/uniseg v0.4.7 // indirect + github.com/russross/blackfriday/v2 v2.1.0 // indirect github.com/spf13/pflag v1.0.5 // indirect github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect golang.org/x/sync v0.7.0 // indirect diff --git a/go.sum b/go.sum index eef66a1..c290dc6 100644 --- a/go.sum +++ b/go.sum @@ -14,6 +14,7 @@ github.com/charmbracelet/x/term v0.1.1 h1:3cosVAiPOig+EV4X9U+3LDgtwwAoEzJjNdwbXD github.com/charmbracelet/x/term v0.1.1/go.mod h1:wB1fHt5ECsu3mXYusyzcngVWWlu1KKUmmLhfgr/Flxw= github.com/charmbracelet/x/windows v0.1.0 h1:gTaxdvzDM5oMa/I2ZNF7wN78X/atWemG9Wph7Ika2k4= github.com/charmbracelet/x/windows v0.1.0/go.mod h1:GLEO/l+lizvFDBPLIOk+49gdX49L9YWMB5t+DZd0jkQ= +github.com/cpuguy83/go-md2man/v2 v2.0.4 h1:wfIWP927BUkWJb2NmU/kNDYIBTh/ziUX91+lVfRxZq4= github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -44,6 +45,7 @@ github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJ github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ= github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= +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/spf13/cobra v1.8.1 h1:e5/vxKd/rZsfSJMUX1agtjeTDf+qv1/JdBF8gg5k9ZM= github.com/spf13/cobra v1.8.1/go.mod h1:wHxEcudfqmLYa8iTfL+OuZPbBZkmvliBWKIezN3kD9Y= diff --git a/internal/generate/docs/main.go b/internal/generate/docs/main.go new file mode 100644 index 0000000..d79b91f --- /dev/null +++ b/internal/generate/docs/main.go @@ -0,0 +1,21 @@ +package main + +import ( + "os" + + "github.com/gabe565/cli-of-life/cmd" + "github.com/spf13/cobra/doc" +) + +func main() { + output := "./docs" + + if err := os.MkdirAll(output, 0o755); err != nil { + panic(err) + } + + root := cmd.New() + if err := doc.GenMarkdownTree(root, output); err != nil { + panic(err) + } +}