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