diff --git a/README.md b/README.md index d504199..634b44c 100644 --- a/README.md +++ b/README.md @@ -67,6 +67,7 @@ The binary has the following options: ```sh Flags: -r, --add-schema-reference "add reference to schema in values.yaml if not found" + -a, --append-newline append newline to generated jsonschema at the end of the file -c, --chart-search-root string "directory to search recursively within for charts (default ".")" -x, --dont-strip-helm-docs-prefix "disable the removal of the helm-docs prefix (--)" -d, --dry-run "don't actually create files just print to stdout passed" diff --git a/cmd/helm-schema/cli.go b/cmd/helm-schema/cli.go index 00eaad9..3e5b81a 100644 --- a/cmd/helm-schema/cli.go +++ b/cmd/helm-schema/cli.go @@ -50,6 +50,8 @@ func newCommand(run func(cmd *cobra.Command, args []string) error) (*cobra.Comma StringP("chart-search-root", "c", ".", "directory to search recursively within for charts") cmd.PersistentFlags(). BoolP("dry-run", "d", false, "don't actually create files just print to stdout passed") + cmd.PersistentFlags(). + BoolP("append-newline", "a", false, "append newline to generated jsonschema at the end of the file") cmd.PersistentFlags(). BoolP("keep-full-comment", "s", false, "keep the whole leading comment (default: cut at empty line)") cmd.PersistentFlags(). diff --git a/cmd/helm-schema/main.go b/cmd/helm-schema/main.go index 5158507..b3be00b 100644 --- a/cmd/helm-schema/main.go +++ b/cmd/helm-schema/main.go @@ -48,6 +48,7 @@ func exec(cmd *cobra.Command, _ []string) error { uncomment := viper.GetBool("uncomment") outFile := viper.GetString("output-file") dontRemoveHelmDocsPrefix := viper.GetBool("dont-strip-helm-docs-prefix") + appendNewline := viper.GetBool("append-newline") if err := viper.UnmarshalKey("value-files", &valueFileNames); err != nil { return err } @@ -237,9 +238,17 @@ loop: continue } + if appendNewline { + jsonStr = append(jsonStr, '\n') + } + if dryRun { log.Infof("Printing jsonschema for %s chart (%s)", result.Chart.Name, result.ChartPath) - fmt.Printf("%s\n", jsonStr) + if appendNewline { + fmt.Printf("%s", jsonStr) + } else { + fmt.Printf("%s\n", jsonStr) + } } else { chartBasePath := filepath.Dir(result.ChartPath) if err := os.WriteFile(filepath.Join(chartBasePath, outFile), jsonStr, 0644); err != nil {