Skip to content

Commit

Permalink
add print --export option
Browse files Browse the repository at this point in the history
  • Loading branch information
jippi committed Apr 4, 2024
1 parent d18463b commit f532915
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 0 deletions.
5 changes: 5 additions & 0 deletions cmd/print/print.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ func NewCommand() *cobra.Command {
}

cmd.Flags().Bool("pretty", false, "implies --color --comments --blank-lines --group-banners")
cmd.Flags().Bool("export", false, "prefix all key/value pairs with [export] statement")

cmd.Flags().String("key-prefix", "", "Filter by key prefix")
cmd.Flags().String("group", "", "Filter by group name")
Expand Down Expand Up @@ -99,5 +100,9 @@ func setup(cmd *cobra.Command) (*ast.Document, *render.Settings, error) {
settings.Apply(render.WithFormattedOutput(true))
}

if boolFlag("export") {
settings.Apply(render.WithExport(true))
}

return doc, settings, allErrors
}
4 changes: 4 additions & 0 deletions pkg/render/output_colorized.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ func (ColorizedOutput) Assignment(ctx context.Context, assignment *ast.Assignmen
printer.Danger().Print("#")
}

if settings.export {
printer.Dark().Print("export ")
}

val := assignment.Literal

if settings.InterpolatedValues {
Expand Down
4 changes: 4 additions & 0 deletions pkg/render/output_plain.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ func (PlainOutput) Assignment(ctx context.Context, assignment *ast.Assignment, s
buf.WriteString("#")
}

if settings.export {
buf.WriteString("export ")
}

val := assignment.Literal

if settings.InterpolatedValues {
Expand Down
1 change: 1 addition & 0 deletions pkg/render/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type Settings struct {
showComments bool
ShowGroupBanners bool
formatOutput bool
export bool
InterpolatedValues bool
outputter Output
}
Expand Down
6 changes: 6 additions & 0 deletions pkg/render/settings_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ func WithFormattedOutput(boolean bool) SettingsOption {
}
}

func WithExport(boolean bool) SettingsOption {
return func(s *Settings) {
s.export = boolean
}
}

func WithInterpolation(b bool) SettingsOption {
return func(s *Settings) {
s.InterpolatedValues = b
Expand Down

0 comments on commit f532915

Please sign in to comment.