Skip to content

Commit

Permalink
feat: add example usage mode flag + generator config
Browse files Browse the repository at this point in the history
Signed-off-by: Matthew Rose <[email protected]>
  • Loading branch information
matty-rose committed Nov 27, 2021
1 parent 5e20787 commit fd0f058
Show file tree
Hide file tree
Showing 6 changed files with 134 additions and 9 deletions.
15 changes: 14 additions & 1 deletion cmd/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ package cmd
import (
"github.com/pkg/errors"
"github.com/spf13/cobra"
"github.com/thediveo/enumflag"

"github.com/matty-rose/gha-docs/pkg/generator"
"github.com/matty-rose/gha-docs/pkg/parser"
Expand All @@ -39,6 +40,9 @@ var outputFile string
// Inject flag
var inject bool

// Usage mode flag
var usageMode generator.UsageMode = generator.Remote

// generateCmd represents the generate command
var generateCmd = &cobra.Command{
Use: "generate [PATH]",
Expand All @@ -51,7 +55,10 @@ var generateCmd = &cobra.Command{
}

var g generator.Generator
g, err = generator.New(format)
g, err = generator.New(generator.Config{
Format: format,
ExampleUsageMode: &usageMode,
})
if err != nil {
return errors.Wrap(err, "couldn't construct the generator")
}
Expand Down Expand Up @@ -89,5 +96,11 @@ func init() {
false,
"Set flag to inject generated documentation between markers. Ignored if not writing to a file. Defaults to false.",
)
generateCmd.PersistentFlags().VarP(
enumflag.New(&usageMode, "mode", generator.UsageModeIDs, enumflag.EnumCaseInsensitive),
"usage-mode",
"u",
"Sets the usage mode when generating example usage block. Must be one of 'remote' or 'local'.",
)
rootCmd.AddCommand(generateCmd)
}
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ require (
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/subosito/gotenv v1.2.0 // indirect
github.com/thediveo/enumflag v0.10.1 // indirect
golang.org/x/sys v0.0.0-20210823070655-63515b42dcdf // indirect
golang.org/x/text v0.3.6 // indirect
gopkg.in/ini.v1 v1.63.2 // indirect
Expand Down
Loading

0 comments on commit fd0f058

Please sign in to comment.