Skip to content

Commit

Permalink
Merge pull request #36 from gandrejczuk/feature/add-linebreak
Browse files Browse the repository at this point in the history
 Append line-break to generated JSON schemas.
  • Loading branch information
dadav authored Aug 8, 2024
2 parents fc0a4c1 + 00fb292 commit 82590e8
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 2 additions & 0 deletions cmd/helm-schema/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -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().
Expand Down
11 changes: 10 additions & 1 deletion cmd/helm-schema/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 82590e8

Please sign in to comment.