Skip to content

Commit

Permalink
feat: now the documentation for the pizza-cli can be generated via pi…
Browse files Browse the repository at this point in the history
…zza docs
  • Loading branch information
nickytonline committed Sep 4, 2024
1 parent cd4b8da commit f63ca9f
Show file tree
Hide file tree
Showing 9 changed files with 137 additions and 4 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@

> All notable changes to this project will be documented in this file
## [1.3.0-beta.3](https://github.com/open-sauced/pizza-cli/compare/v1.3.0-beta.2...v1.3.0-beta.3) (2024-09-04)


### 🐛 Bug Fixes

* NPM cache now looks at package-lock file ([#136](https://github.com/open-sauced/pizza-cli/issues/136)) ([cd4b8da](https://github.com/open-sauced/pizza-cli/commit/cd4b8da75e1a0c0aa3d7e6f76d6b560a4dea941f))

## [1.3.0-beta.2](https://github.com/open-sauced/pizza-cli/compare/v1.3.0-beta.1...v1.3.0-beta.2) (2024-09-04)


Expand Down
62 changes: 62 additions & 0 deletions cmd/docs/docs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package docs

import (
"fmt"
"os"
"path/filepath"

"github.com/spf13/cobra"
"github.com/spf13/cobra/doc"
)

type Options struct {
// the path location to generate the documentation
path string
}

const DefaultPath = "./docs"

func NewDocsCommand() *cobra.Command {
opts := &Options{}

return &cobra.Command{
Use: "docs",
Short: "Generates the documentation for the CLI",
Args: cobra.MaximumNArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
// Use default path if no argument is provided
if len(args) == 0 {
opts.path = DefaultPath
fmt.Printf("No path was provided. Using default path: %s\n", DefaultPath)
} else {
absPath, err := filepath.Abs(args[0])
if err != nil {
return err
}
opts.path = absPath
}

// Create the directory if it doesn't exist
_, err := os.Stat(opts.path)
if os.IsNotExist(err) {
fmt.Printf("The directory %s does not exist. Creating it...\n", opts.path)

err := os.MkdirAll(opts.path, os.ModePerm)
if err != nil {
return fmt.Errorf("error creating documentation output directory %s: %s", opts.path, err)
}
}

// Generate markdown documentation
fmt.Printf("Generating documentation in %s...\n", opts.path)
err = doc.GenMarkdownTree(cmd, opts.path)
if err != nil {
return err
}

fmt.Printf("Finished generating documentation in %s\n", opts.path)

return nil
},
}
}
2 changes: 2 additions & 0 deletions cmd/root/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/spf13/cobra"

"github.com/open-sauced/pizza-cli/cmd/auth"
"github.com/open-sauced/pizza-cli/cmd/docs"
"github.com/open-sauced/pizza-cli/cmd/generate"
"github.com/open-sauced/pizza-cli/cmd/insights"
"github.com/open-sauced/pizza-cli/cmd/version"
Expand Down Expand Up @@ -43,6 +44,7 @@ func NewRootCommand() (*cobra.Command, error) {
cmd.AddCommand(generate.NewGenerateCommand())
cmd.AddCommand(insights.NewInsightsCommand())
cmd.AddCommand(version.NewVersionCommand())
cmd.AddCommand(docs.NewDocsCommand())

err := cmd.PersistentFlags().MarkHidden(constants.FlagNameEndpoint)
if err != nil {
Expand Down
28 changes: 28 additions & 0 deletions docs/pizza_docs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
## pizza docs

Generates the documentation for the CLI

```
pizza docs [flags]
```

### Options

```
-h, --help help for docs
```

### Options inherited from parent commands

```
-c, --config string The saucectl config (default "~/.sauced.yaml")
--disable-telemetry Disable sending telemetry data to OpenSauced
-l, --log-level string The logging level. Options: error, warn, info, debug (default "info")
--tty-disable Disable log stylization. Suitable for CI/CD and automation
```

### SEE ALSO

* [pizza](pizza.md) - OpenSauced CLI

###### Auto generated by spf13/cobra on 4-Sep-2024
28 changes: 28 additions & 0 deletions docs2/pizza_docs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
## pizza docs

Generates the documentation for the CLI

```
pizza docs [flags]
```

### Options

```
-h, --help help for docs
```

### Options inherited from parent commands

```
-c, --config string The saucectl config (default "~/.sauced.yaml")
--disable-telemetry Disable sending telemetry data to OpenSauced
-l, --log-level string The logging level. Options: error, warn, info, debug (default "info")
--tty-disable Disable log stylization. Suitable for CI/CD and automation
```

### SEE ALSO

* [pizza](pizza.md) - OpenSauced CLI

###### Auto generated by spf13/cobra on 4-Sep-2024
6 changes: 5 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ require (
gopkg.in/yaml.v3 v3.0.1
)

require github.com/charmbracelet/bubbletea v0.27.1 // indirect
require (
github.com/charmbracelet/bubbletea v0.27.1 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.4 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
)

require (
dario.cat/mergo v1.0.0 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ github.com/cli/browser v1.3.0/go.mod h1:HH8s+fOAxjhQoBUAsKuPCbqUuxZDhQ2/aD+SzsEf
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.4 h1:wfIWP927BUkWJb2NmU/kNDYIBTh/ziUX91+lVfRxZq4=
github.com/cpuguy83/go-md2man/v2 v2.0.4/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=
Expand Down Expand Up @@ -107,6 +108,7 @@ github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
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.2-0.20230802210424-5b0b94c5c0d3 h1:n661drycOFuPLCN3Uc8sB6B/s6Z4t2xvBgU1htSHuq8=
github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3/go.mod h1:A0bzQcvG0E7Rwjx0REVgAGH58e96+X0MeOfepqsbeW4=
Expand Down
4 changes: 2 additions & 2 deletions npm/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion npm/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pizza",
"version": "1.3.0-beta.2",
"version": "1.3.0-beta.3",
"description": "A command line utility for insights, metrics, and all things OpenSauced",
"repository": "https://github.com/open-sauced/pizza-cli",
"license": "MIT",
Expand Down

0 comments on commit f63ca9f

Please sign in to comment.