Skip to content

Commit

Permalink
Adds flag to disable quotes in TextFormatter
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Lacroix committed Apr 23, 2020
1 parent 91ef3ab commit c7455de
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
6 changes: 6 additions & 0 deletions text_formatter.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ type TextFormatter struct {
// Force quoting of all values
ForceQuote bool

// DisableQuote disables quoting for all values
DisableQuote bool

// Override coloring based on CLICOLOR and CLICOLOR_FORCE. - https://bixense.com/clicolors/
EnvironmentOverrideColors bool

Expand Down Expand Up @@ -292,6 +295,9 @@ func (f *TextFormatter) needsQuoting(text string) bool {
if f.QuoteEmptyFields && len(text) == 0 {
return true
}
if f.DisableQuote {
return false
}
for _, ch := range text {
if !((ch >= 'a' && ch <= 'z') ||
(ch >= 'A' && ch <= 'Z') ||
Expand Down
8 changes: 8 additions & 0 deletions text_formatter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@ func TestQuoting(t *testing.T) {
checkQuoting(false, errors.New("invalid"))
checkQuoting(true, errors.New("invalid argument"))

// Test for quoting disabled
tf.DisableQuote = true
checkQuoting(false, "")
checkQuoting(false, "abcd")
checkQuoting(false, "foo\n\rbar")
checkQuoting(false, errors.New("invalid argument"))
tf.DisableQuote = false

// Test for quoting empty fields.
tf.QuoteEmptyFields = true
checkQuoting(true, "")
Expand Down

0 comments on commit c7455de

Please sign in to comment.