|
|
|
@ -6,7 +6,6 @@ import (
|
|
|
|
|
"io" |
|
|
|
|
"os" |
|
|
|
|
|
|
|
|
|
"github.com/burntSushi/toml" |
|
|
|
|
"github.com/spf13/cobra" |
|
|
|
|
"gopkg.in/yaml.v3" |
|
|
|
|
) |
|
|
|
@ -20,8 +19,8 @@ type Encoder interface {
|
|
|
|
|
type Encoding int |
|
|
|
|
|
|
|
|
|
const ( |
|
|
|
|
// TOMLEncoding represents TOML encoding
|
|
|
|
|
TOMLEncoding Encoding = iota |
|
|
|
|
// UndefinedEncoding implies the default encoding
|
|
|
|
|
UndefinedEncoding Encoding = iota |
|
|
|
|
// JSONEncoding represents JSON encoding
|
|
|
|
|
JSONEncoding |
|
|
|
|
// YAMLEncoding represents YAML encoding
|
|
|
|
@ -42,12 +41,6 @@ func NewYAMLEncoder(w io.Writer) Encoder {
|
|
|
|
|
return enc |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// NewTOMLEncoder returns a TOML [Encoder] to work on the given [io.Writer]
|
|
|
|
|
func NewTOMLEncoder(w io.Writer) Encoder { |
|
|
|
|
enc := toml.NewEncoder(w) |
|
|
|
|
return enc |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const encoding = YAMLEncoding |
|
|
|
|
|
|
|
|
|
// Command
|
|
|
|
@ -66,10 +59,8 @@ var dumpCmd = &cobra.Command{
|
|
|
|
|
switch encoding { |
|
|
|
|
case JSONEncoding: |
|
|
|
|
enc = NewJSONEncoder(&buf) |
|
|
|
|
case YAMLEncoding: |
|
|
|
|
enc = NewYAMLEncoder(&buf) |
|
|
|
|
default: |
|
|
|
|
enc = NewTOMLEncoder(&buf) |
|
|
|
|
enc = NewYAMLEncoder(&buf) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if err = enc.Encode(m); err != nil { |
|
|
|
|