Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added scalar output for TOML (#1617)
- Loading branch information
Showing
5 changed files
with
88 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package yqlib | ||
|
||
import ( | ||
"fmt" | ||
"io" | ||
|
||
yaml "gopkg.in/yaml.v3" | ||
) | ||
|
||
type tomlEncoder struct { | ||
} | ||
|
||
func NewTomlEncoder() Encoder { | ||
return &tomlEncoder{} | ||
} | ||
|
||
func (te *tomlEncoder) Encode(writer io.Writer, node *yaml.Node) error { | ||
if node.Kind == yaml.ScalarNode { | ||
return writeString(writer, node.Value+"\n") | ||
} | ||
return fmt.Errorf("only scalars (e.g. strings, numbers, booleans) are supported for TOML output at the moment. Please use yaml output format (-oy) until the encoder has been fully implemented") | ||
} | ||
|
||
func (te *tomlEncoder) PrintDocumentSeparator(writer io.Writer) error { | ||
return nil | ||
} | ||
|
||
func (te *tomlEncoder) PrintLeadingContent(writer io.Writer, content string) error { | ||
return nil | ||
} | ||
|
||
func (te *tomlEncoder) CanHandleAliases() bool { | ||
return false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters