Skip to content

Commit

Permalink
Merge pull request #242 from buty4649/disable-colorize-in-json-raw-ou…
Browse files Browse the repository at this point in the history
…tput

Disable colorize in json raw output(-j -r)
  • Loading branch information
buty4649 authored Dec 5, 2024
2 parents e652354 + b722774 commit 7e29131
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
6 changes: 1 addition & 5 deletions mrblib/rf/00filter/json.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,7 @@ def format(val, record)

def string_to_json(str)
if raw?
if colorize
JSON.colorize(str, JSON.color_string)
else
str
end
str
else
str.to_json(colorize:, pretty_print:)
end
Expand Down
15 changes: 11 additions & 4 deletions spec/filter/json_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,19 @@
context 'with -r option' do
describe 'Output string' do
let(:input) { load_fixture('json/string.json') }
let(:output) { 'test' }
let(:args) { '-j -r _' }
let(:expect_output) { "test\n" }

before { run_rf('-j -r _', input) }
it_behaves_like 'a successful exec'
end

it { expect(last_command_started).to be_successfully_executed }
it { expect(last_command_started).to have_output output_string_eq output }
# When using pipes, `--no-color` is implicitly applied internally, so we explicitly test for it.
context 'with --color option' do
let(:input) { load_fixture('json/string.json') }
let(:args) { '-j -r --color _' }
let(:expect_output) { "test\n" }

it_behaves_like 'a successful exec'
end
end

Expand Down

0 comments on commit 7e29131

Please sign in to comment.