Add cmd/gotoml-test-encoder (#907)

This commit is contained in:
Martin Tournoij
2023-10-23 22:40:44 +02:00
committed by GitHub
parent a76e18e8c5
commit fd8d0bf4d9
4 changed files with 72 additions and 5 deletions
+18
View File
@@ -48,3 +48,21 @@ func DecodeStdin() error {
return nil
}
// EncodeStdin is a helper function for the toml-test binary interface. Tagged
// JSON is read from STDIN and a resulting TOML representation is written to
// STDOUT.
func EncodeStdin() error {
var j interface{}
err := json.NewDecoder(os.Stdin).Decode(&j)
if err != nil {
return err
}
rm, err := rmTag(j)
if err != nil {
return fmt.Errorf("removing tags: %w", err)
}
return toml.NewEncoder(os.Stdout).Encode(rm)
}