From 7f1a92a1cbf5db2a92397bf1bd6a4a0acf6afa8e Mon Sep 17 00:00:00 2001 From: Grzegorz Andrejczuk Date: Thu, 1 Aug 2024 13:42:21 +0200 Subject: [PATCH 1/2] Add linebreak Append line-break to generated JSON schemas. Signed-off-by: Grzegorz Andrejczuk --- cmd/helm-schema/main.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cmd/helm-schema/main.go b/cmd/helm-schema/main.go index 5158507..59bca9e 100644 --- a/cmd/helm-schema/main.go +++ b/cmd/helm-schema/main.go @@ -237,9 +237,11 @@ loop: continue } + jsonStr = append(jsonStr, '\n') + if dryRun { log.Infof("Printing jsonschema for %s chart (%s)", result.Chart.Name, result.ChartPath) - fmt.Printf("%s\n", jsonStr) + fmt.Print(jsonStr) } else { chartBasePath := filepath.Dir(result.ChartPath) if err := os.WriteFile(filepath.Join(chartBasePath, outFile), jsonStr, 0644); err != nil { From 00fb292fb55f1a44338bbcb525af08031c773fdf Mon Sep 17 00:00:00 2001 From: dadav <33197631+dadav@users.noreply.github.com> Date: Thu, 8 Aug 2024 19:31:08 +0200 Subject: [PATCH 2/2] fix: Make newline optional --- README.md | 1 + cmd/helm-schema/cli.go | 2 ++ cmd/helm-schema/main.go | 11 +++++++++-- 3 files changed, 12 insertions(+), 2 deletions(-) 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 59bca9e..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,11 +238,17 @@ loop: continue } - jsonStr = append(jsonStr, '\n') + if appendNewline { + jsonStr = append(jsonStr, '\n') + } if dryRun { log.Infof("Printing jsonschema for %s chart (%s)", result.Chart.Name, result.ChartPath) - fmt.Print(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 {