Skip to content

Commit

Permalink
Merge pull request sirupsen#1042 from sirupsen/ffz/ForceQuote
Browse files Browse the repository at this point in the history
ForceQuote option to TextFormatter
  • Loading branch information
Edward Muller authored Oct 23, 2019
2 parents b870132 + b8016f8 commit e0509fc
Show file tree
Hide file tree
Showing 2 changed files with 12 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 @@ -34,6 +34,9 @@ type TextFormatter struct {
// Force disabling colors.
DisableColors bool

// Force quoting of all values
ForceQuote bool

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

Expand Down Expand Up @@ -283,6 +286,9 @@ func (f *TextFormatter) printColored(b *bytes.Buffer, entry *Entry, keys []strin
}

func (f *TextFormatter) needsQuoting(text string) bool {
if f.ForceQuote {
return true
}
if f.QuoteEmptyFields && len(text) == 0 {
return true
}
Expand Down
6 changes: 6 additions & 0 deletions text_formatter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ func TestQuoting(t *testing.T) {
checkQuoting(true, "")
checkQuoting(false, "abcd")
checkQuoting(true, errors.New("invalid argument"))

// Test forcing quotes.
tf.ForceQuote = true
checkQuoting(true, "")
checkQuoting(true, "abcd")
checkQuoting(true, errors.New("invalid argument"))
}

func TestEscaping(t *testing.T) {
Expand Down

0 comments on commit e0509fc

Please sign in to comment.