Skip to content

Commit

Permalink
cleanup code
Browse files Browse the repository at this point in the history
  • Loading branch information
xrstf committed Jan 5, 2024
1 parent 5248741 commit 1adf32a
Showing 1 changed file with 5 additions and 16 deletions.
21 changes: 5 additions & 16 deletions cmd/rudi/encoding/decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func Decode(input io.Reader, enc types.Encoding) (any, error) {
case types.YamlEncoding:
decoded, err := decodeYaml(input)
if err != nil {
return nil, fmt.Errorf("failed to parse file as JSON5: %w", err)
return nil, err
}

switch len(decoded) {
Expand All @@ -76,23 +76,12 @@ func Decode(input io.Reader, enc types.Encoding) (any, error) {
}

case types.YamlDocumentsEncoding:
decoder := yaml.NewDecoder(input)

documents := []any{}
for {
var doc any
if err := decoder.Decode(&doc); err != nil {
if errors.Is(err, io.EOF) {
break
}

return nil, fmt.Errorf("failed to parse file as YAML: %w", err)
}

documents = append(documents, doc)
decoded, err := decodeYaml(input)
if err != nil {
return nil, err
}

data = documents
data = decoded

case types.TomlEncoding:
decoder := toml.NewDecoder(input)
Expand Down

0 comments on commit 1adf32a

Please sign in to comment.