Skip to content

Commit

Permalink
commands: Add missing gen docshelper command
Browse files Browse the repository at this point in the history
Updates #10953
  • Loading branch information
bep committed May 22, 2023
1 parent 288be19 commit 943ff7f
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions commands/gen.go
Expand Up @@ -15,6 +15,7 @@ package commands

import (
"context"
"encoding/json"
"fmt"
"os"
"path"
Expand All @@ -26,6 +27,7 @@ import (
"github.com/alecthomas/chroma/v2/styles"
"github.com/bep/simplecobra"
"github.com/gohugoio/hugo/common/hugo"
"github.com/gohugoio/hugo/docshelper"
"github.com/gohugoio/hugo/helpers"
"github.com/gohugoio/hugo/hugofs"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -174,11 +176,47 @@ url: %s

}

var docsHelperTarget string

newDocsHelper := func() simplecobra.Commander {
return &simpleCommand{
name: "docshelper",
short: "Generate some data files for the Hugo docs.",

run: func(ctx context.Context, cd *simplecobra.Commandeer, r *rootCommand, args []string) error {
r.Println("Generate docs data to", docsHelperTarget)

targetFile := filepath.Join(docsHelperTarget, "docs.json")

f, err := os.Create(targetFile)
if err != nil {
return err
}
defer f.Close()

enc := json.NewEncoder(f)
enc.SetIndent("", " ")

if err := enc.Encode(docshelper.GetDocProvider()); err != nil {
return err
}

r.Println("Done!")
return nil
},
withc: func(cmd *cobra.Command) {
cmd.Hidden = true
cmd.PersistentFlags().StringVarP(&docsHelperTarget, "dir", "", "docs/data", "data dir")
},
}
}

return &genCommand{
commands: []simplecobra.Commander{
newChromaStyles(),
newGen(),
newMan(),
newDocsHelper(),
},
}

Expand Down

0 comments on commit 943ff7f

Please sign in to comment.