From 007cacdd34fb44ebc12a24c0ebf11abad85bc6e6 Mon Sep 17 00:00:00 2001 From: Edward Muller Date: Mon, 14 Oct 2019 22:53:51 -0700 Subject: [PATCH] Force Quote Closed #1005 --- text_formatter.go | 6 ++++++ text_formatter_test.go | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/text_formatter.go b/text_formatter.go index f08563e..5867b25 100644 --- a/text_formatter.go +++ b/text_formatter.go @@ -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 @@ -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 } diff --git a/text_formatter_test.go b/text_formatter_test.go index 99b5d8c..5d94ebb 100644 --- a/text_formatter_test.go +++ b/text_formatter_test.go @@ -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) {