Skip to content

Commit

Permalink
feat: add option to disable removal of helm-docs prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
dadav committed Sep 15, 2023
1 parent 3cadf94 commit 734eb2d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
2 changes: 2 additions & 0 deletions cmd/helm-schema/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ func newCommand(run func(cmd *cobra.Command, args []string) error) (*cobra.Comma
BoolP("dry-run", "d", false, "don't actually create files just print to stdout passed")
cmd.PersistentFlags().
BoolP("keep-full-comment", "s", false, "Keep the whole leading comment (default: cut at empty line)")
cmd.PersistentFlags().
BoolP("dont-strip-helm-docs-prefix", "x", false, "Disable the removal of the helm-docs prefix (--)")
cmd.PersistentFlags().
BoolP("no-dependencies", "n", false, "don't analyze dependencies")
cmd.PersistentFlags().StringP("log-level", "l", "info", logLevelUsage)
Expand Down
6 changes: 4 additions & 2 deletions cmd/helm-schema/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ type Result struct {
}

func worker(
dryRun, keepFullComment bool,
dryRun, keepFullComment, dontRemoveHelmDocsPrefix bool,
valueFileNames []string,
outFile string,
queue <-chan string,
Expand Down Expand Up @@ -120,7 +120,7 @@ func worker(
continue
}

result.Schema = schema.YamlToSchema(&values, keepFullComment, nil)
result.Schema = schema.YamlToSchema(&values, keepFullComment, dontRemoveHelmDocsPrefix, nil)

results <- result
}
Expand All @@ -135,6 +135,7 @@ func exec(cmd *cobra.Command, _ []string) error {
keepFullComment := viper.GetBool("keep-full-comment")
outFile := viper.GetString("output-file")
valueFileNames := viper.GetStringSlice("value-files")
dontRemoveHelmDocsPrefix := viper.GetBool("dont-strip-helm-docs-prefix")
workersCount := runtime.NumCPU() * 2

// 1. Start a producer that searches Chart.yaml and values.yaml files
Expand All @@ -161,6 +162,7 @@ func exec(cmd *cobra.Command, _ []string) error {
worker(
dryRun,
keepFullComment,
dontRemoveHelmDocsPrefix,
valueFileNames,
outFile,
queue,
Expand Down
9 changes: 8 additions & 1 deletion pkg/schema/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ func GetSchemaFromComment(comment string) (Schema, string, error) {
func YamlToSchema(
node *yaml.Node,
keepFullComment bool,
dontRemoveHelmDocsPrefix bool,
parentRequiredProperties *[]string,
) Schema {
var schema Schema
Expand All @@ -310,6 +311,7 @@ func YamlToSchema(
schema.Properties = YamlToSchema(
node.Content[0],
keepFullComment,
dontRemoveHelmDocsPrefix,
&requiredProperties,
).Properties

Expand Down Expand Up @@ -345,6 +347,10 @@ func YamlToSchema(
if err != nil {
log.Fatalf("Error while parsing comment of key %s: %v", keyNode.Value, err)
}
if !dontRemoveHelmDocsPrefix {
prefixRemover := regexp.MustCompile(`(?m)^--\s?`)
description = prefixRemover.ReplaceAllString(description, "")
}

if keyNodeSchema.HasData {
if err := keyNodeSchema.Validate(); err != nil {
Expand Down Expand Up @@ -394,6 +400,7 @@ func YamlToSchema(
keyNodeSchema.Properties = YamlToSchema(
valueNode,
keepFullComment,
dontRemoveHelmDocsPrefix,
&requiredProperties,
).Properties
if len(requiredProperties) > 0 {
Expand All @@ -413,7 +420,7 @@ func YamlToSchema(
seqSchema.AnyOf = append(seqSchema.AnyOf, &Schema{Type: itemNodeType})
} else {
itemRequiredProperties := []string{}
itemSchema := YamlToSchema(itemNode, keepFullComment, &itemRequiredProperties)
itemSchema := YamlToSchema(itemNode, keepFullComment, dontRemoveHelmDocsPrefix, &itemRequiredProperties)

if len(itemRequiredProperties) > 0 {
itemSchema.RequiredProperties = itemRequiredProperties
Expand Down

0 comments on commit 734eb2d

Please sign in to comment.