Skip to content

Commit

Permalink
chore: separate docs:generate (#4242)
Browse files Browse the repository at this point in the history
  • Loading branch information
knqyf263 authored May 10, 2023
1 parent 37b25d2 commit ec3906c
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 18 deletions.
28 changes: 28 additions & 0 deletions magefiles/docs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//go:build mage_docs

package main

import (
"github.com/spf13/cobra/doc"

"github.com/aquasecurity/trivy/pkg/commands"
"github.com/aquasecurity/trivy/pkg/flag"
"github.com/aquasecurity/trivy/pkg/log"
)

// Generate CLI references
func main() {
ver, err := version()
if err != nil {
log.Fatal(err)
}
// Set a dummy path for the documents
flag.CacheDirFlag.Value = "/path/to/cache"
flag.ModuleDirFlag.Value = "$HOME/.trivy/modules"

cmd := commands.NewApp(ver)
cmd.DisableAutoGenTag = true
if err = doc.GenMarkdownTree(cmd, "./docs/docs/references/configuration/cli"); err != nil {
log.Fatal(err)
}
}
19 changes: 1 addition & 18 deletions magefiles/magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ import (
"github.com/magefile/mage/mg"
"github.com/magefile/mage/sh"
"github.com/magefile/mage/target"
"github.com/spf13/cobra/doc"

"github.com/aquasecurity/trivy/pkg/commands"
"github.com/aquasecurity/trivy/pkg/flag"
)

var (
Expand Down Expand Up @@ -344,20 +340,7 @@ func (Docs) Serve() error {

// Generate generates CLI references
func (Docs) Generate() error {
ver, err := version()
if err != nil {
return err
}
// Set a dummy path for the documents
flag.CacheDirFlag.Value = "/path/to/cache"
flag.ModuleDirFlag.Value = "$HOME/.trivy/modules"

cmd := commands.NewApp(ver)
cmd.DisableAutoGenTag = true
if err = doc.GenMarkdownTree(cmd, "./docs/docs/references/configuration/cli"); err != nil {
return err
}
return nil
return sh.RunWith(ENV, "go", "run", "-tags=mage_docs", "./magefiles")
}

func findProtoFiles() ([]string, error) {
Expand Down

0 comments on commit ec3906c

Please sign in to comment.