diff --git a/pkg/yqlib/encoder_base64.go b/pkg/yqlib/encoder_base64.go index 0b98a733341..11ef5a253b5 100644 --- a/pkg/yqlib/encoder_base64.go +++ b/pkg/yqlib/encoder_base64.go @@ -28,7 +28,7 @@ func (e *base64Encoder) PrintLeadingContent(_ io.Writer, _ string) error { func (e *base64Encoder) Encode(writer io.Writer, node *CandidateNode) error { if node.guessTagFromCustomType() != "!!str" { - return fmt.Errorf("cannot encode %v as base64, can only operate on strings. Please first pipe through another encoding operator to convert the value to a string", node.Tag) + return fmt.Errorf("cannot encode %v as base64, can only operate on strings", node.Tag) } _, err := writer.Write([]byte(e.encoding.EncodeToString([]byte(node.Value)))) return err diff --git a/pkg/yqlib/operator_encoder_decoder.go b/pkg/yqlib/operator_encoder_decoder.go index a5e4b4eb569..03d8c3432a9 100644 --- a/pkg/yqlib/operator_encoder_decoder.go +++ b/pkg/yqlib/operator_encoder_decoder.go @@ -18,12 +18,6 @@ func configureEncoder(format *PrinterOutputFormat, indent int) Encoder { prefs.ColorsEnabled = false prefs.UnwrapScalar = false return NewJSONEncoder(prefs) - case PropsOutputFormat: - return NewPropertiesEncoder(ConfiguredPropertiesPreferences) - case CSVOutputFormat: - return NewCsvEncoder(ConfiguredCsvPreferences) - case TSVOutputFormat: - return NewCsvEncoder(ConfiguredTsvPreferences) case YamlOutputFormat: var prefs = ConfiguredYamlPreferences.Copy() prefs.Indent = indent @@ -33,14 +27,8 @@ func configureEncoder(format *PrinterOutputFormat, indent int) Encoder { var xmlPrefs = ConfiguredXMLPreferences.Copy() xmlPrefs.Indent = indent return NewXMLEncoder(xmlPrefs) - case Base64OutputFormat: - return NewBase64Encoder() - case UriOutputFormat: - return NewUriEncoder() - case ShOutputFormat: - return NewShEncoder() } - panic("invalid encoder") + return format.EncoderFactory() } func encodeToString(candidate *CandidateNode, prefs encoderPreferences) (string, error) { diff --git a/pkg/yqlib/printer.go b/pkg/yqlib/printer.go index afa0ef582b7..d64e21329e9 100644 --- a/pkg/yqlib/printer.go +++ b/pkg/yqlib/printer.go @@ -33,9 +33,9 @@ var CSVOutputFormat = &PrinterOutputFormat{"csv", []string{"c"}, func() Encoder var TSVOutputFormat = &PrinterOutputFormat{"tsv", []string{"t"}, func() Encoder { return NewCsvEncoder(ConfiguredTsvPreferences) }} var XMLOutputFormat = &PrinterOutputFormat{"xml", []string{"x"}, func() Encoder { return NewXMLEncoder(ConfiguredXMLPreferences) }} -var Base64OutputFormat = &PrinterOutputFormat{} -var UriOutputFormat = &PrinterOutputFormat{} -var ShOutputFormat = &PrinterOutputFormat{} +var Base64OutputFormat = &PrinterOutputFormat{"base64", []string{}, func() Encoder { return NewBase64Encoder() }} +var UriOutputFormat = &PrinterOutputFormat{"uri", []string{}, func() Encoder { return NewUriEncoder() }} +var ShOutputFormat = &PrinterOutputFormat{"", nil, func() Encoder { return NewShEncoder() }} var TomlOutputFormat = &PrinterOutputFormat{"toml", []string{}, func() Encoder { return NewTomlEncoder() }} var ShellVariablesOutputFormat = &PrinterOutputFormat{"shell", []string{"s", "sh"}, func() Encoder { return NewShellVariablesEncoder() }}