From 734eb2de45b2690b56dde9320adebe12d86e0cd3 Mon Sep 17 00:00:00 2001 From: dadav <33197631+dadav@users.noreply.github.com> Date: Fri, 15 Sep 2023 19:59:11 +0200 Subject: [PATCH] feat: add option to disable removal of helm-docs prefix --- cmd/helm-schema/cli.go | 2 ++ cmd/helm-schema/main.go | 6 ++++-- pkg/schema/schema.go | 9 ++++++++- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/cmd/helm-schema/cli.go b/cmd/helm-schema/cli.go index d8459e6..79b15e3 100644 --- a/cmd/helm-schema/cli.go +++ b/cmd/helm-schema/cli.go @@ -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) diff --git a/cmd/helm-schema/main.go b/cmd/helm-schema/main.go index 60bdf56..775de83 100644 --- a/cmd/helm-schema/main.go +++ b/cmd/helm-schema/main.go @@ -47,7 +47,7 @@ type Result struct { } func worker( - dryRun, keepFullComment bool, + dryRun, keepFullComment, dontRemoveHelmDocsPrefix bool, valueFileNames []string, outFile string, queue <-chan string, @@ -120,7 +120,7 @@ func worker( continue } - result.Schema = schema.YamlToSchema(&values, keepFullComment, nil) + result.Schema = schema.YamlToSchema(&values, keepFullComment, dontRemoveHelmDocsPrefix, nil) results <- result } @@ -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 @@ -161,6 +162,7 @@ func exec(cmd *cobra.Command, _ []string) error { worker( dryRun, keepFullComment, + dontRemoveHelmDocsPrefix, valueFileNames, outFile, queue, diff --git a/pkg/schema/schema.go b/pkg/schema/schema.go index 7e55fc6..569797f 100644 --- a/pkg/schema/schema.go +++ b/pkg/schema/schema.go @@ -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 @@ -310,6 +311,7 @@ func YamlToSchema( schema.Properties = YamlToSchema( node.Content[0], keepFullComment, + dontRemoveHelmDocsPrefix, &requiredProperties, ).Properties @@ -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 { @@ -394,6 +400,7 @@ func YamlToSchema( keyNodeSchema.Properties = YamlToSchema( valueNode, keepFullComment, + dontRemoveHelmDocsPrefix, &requiredProperties, ).Properties if len(requiredProperties) > 0 { @@ -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