Skip to content

Commit

Permalink
change 'FormatRaw' to 'FormatPlaintext'
Browse files Browse the repository at this point in the history
  • Loading branch information
vdice committed Feb 7, 2019
1 parent ca33883 commit 919e39c
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 41 deletions.
12 changes: 12 additions & 0 deletions pkg/printer/plaintext.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package printer

import (
"fmt"
"io"
)

// PrintPlaintext is a printer that prints the provided value as is
func PrintPlaintext(out io.Writer, v interface{}) error {
fmt.Fprintf(out, `%#v`, v)
return nil
}
43 changes: 43 additions & 0 deletions pkg/printer/plaintext_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package printer

import (
"bytes"
"testing"

"github.com/stretchr/testify/require"
)

type Test struct {
value interface{}
expectedOutput string
}

type specialType struct {
A bool
B float32
}

func TestPrintPlaintext(t *testing.T) {
tests := []Test{
Test{
value: "I'm a string",
expectedOutput: "\"I'm a string\"",
},
Test{
value: []int{1, 2, 3},
expectedOutput: "[]int{1, 2, 3}",
},
Test{
value: specialType{A: true, B: 123},
expectedOutput: "printer.specialType{A:true, B:123}",
},
}

for _, test := range tests {
b := &bytes.Buffer{}
err := PrintPlaintext(b, test.value)

require.Nil(t, err)
require.Equal(t, test.expectedOutput, b.String())
}
}
10 changes: 5 additions & 5 deletions pkg/printer/printer.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ import "github.com/pkg/errors"
type Format string

const (
FormatJson Format = "json"
FormatTable Format = "table"
FormatYaml Format = "yaml"
FormatRaw Format = "raw"
FormatJson Format = "json"
FormatTable Format = "table"
FormatYaml Format = "yaml"
FormatPlaintext Format = "plaintext"
)

func ParseFormat(v string) (Format, error) {
format := Format(v)
switch format {
case FormatTable, FormatJson, FormatYaml, FormatRaw:
case FormatTable, FormatJson, FormatYaml, FormatPlaintext:
return format, nil
default:
return "", errors.Errorf("invalid format: %s", v)
Expand Down
12 changes: 0 additions & 12 deletions pkg/printer/raw.go

This file was deleted.

24 changes: 0 additions & 24 deletions pkg/printer/raw_test.go

This file was deleted.

0 comments on commit 919e39c

Please sign in to comment.