Skip to content
This repository has been archived by the owner on Jun 1, 2023. It is now read-only.

Commit

Permalink
The CLI should not report IO messages when the --json flag is passed (
Browse files Browse the repository at this point in the history
  • Loading branch information
karreiro authored Feb 20, 2023
1 parent b398d33 commit 79c988b
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ From version 2.6.0, the sections in this file adhere to the [keep a changelog](h
### Fixed
* [#2721](https://github.com/Shopify/shopify-cli/pull/2721): Do not `replace_asset_urls` in font bodies
* [#2729](https://github.com/Shopify/shopify-cli/pull/2729): Do not inject hot-reload code into web-pixels-manager sandbox (from cli#1370)
* [#2731](https://github.com/Shopify/shopify-cli/pull/2731): The CLI should not report IO messages when the `--json` flag is passed

### Added
* [#2724](https://github.com/Shopify/shopify-cli/pull/2724): Introduce hidden `--overwrite-json` flag
Expand Down
1 change: 1 addition & 0 deletions lib/project_types/theme/commands/push.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ def call(_args, name)
begin
syncer.start_threads
if options.flags[:json]
syncer.standard_reporter.disable!
syncer.upload_theme!(delete: delete)
else
CLI::UI::Frame.open(@ctx.message("theme.push.info.pushing", theme.name, theme.id, theme.shop)) do
Expand Down
2 changes: 1 addition & 1 deletion lib/shopify_cli/theme/syncer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class Syncer
:union_merge, # - Union merges the local file content with the remote file content
]

attr_reader :ctx, :theme, :checksums, :error_checksums, :api_client, :pending
attr_reader :ctx, :theme, :checksums, :error_checksums, :api_client, :pending, :standard_reporter
attr_accessor :include_filter, :ignore_filter

def_delegators :@error_reporter, :has_any_error?
Expand Down
4 changes: 2 additions & 2 deletions lib/shopify_cli/theme/syncer/standard_reporter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module Theme
class Syncer
##
# ShopifyCLI::Theme::Syncer::StdReporter allows disabling/enabling
# messages reported in the standard output (ShopifyCLI::Context#puts).
# messages reported in the standard error output (ShopifyCLI::Context#puts).
#
class StandardReporter
attr_reader :ctx
Expand All @@ -24,7 +24,7 @@ def enable!
end

def report(message)
ctx.puts(message) if @enabled
ctx.error(message) if @enabled
end
end
end
Expand Down
6 changes: 4 additions & 2 deletions test/project_types/theme/commands/push_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def setup
editor_url: "https://test.myshopify.io/",
live?: false,
)
@syncer = stub("Syncer", lock_io!: nil, unlock_io!: nil, has_any_error?: false)
@syncer = stub("Syncer", lock_io!: nil, unlock_io!: nil, has_any_error?: false, standard_reporter: mock)
@ignore_filter = mock("IgnoreFilter")
@include_filter = mock("IncludeFilter")

Expand Down Expand Up @@ -226,6 +226,7 @@ def test_push_json
@syncer.expects(:start_threads)
@syncer.expects(:shutdown)

@syncer.standard_reporter.expects(:disable!)
@syncer.expects(:upload_theme!).with(delete: true)
@command.expects(:puts).with("{\"theme\":{}}")

Expand All @@ -239,7 +240,8 @@ def test_push_json
end

def test_push_when_syncer_has_an_error_json
syncer = stub("Syncer", lock_io!: nil, unlock_io!: nil, has_any_error?: true)
syncer = stub("Syncer", lock_io!: nil, unlock_io!: nil, has_any_error?: true,
standard_reporter: stub(disable!: nil))

ShopifyCLI::Theme::Theme.expects(:find_by_identifier)
.with(@ctx, root: @root, identifier: 1234)
Expand Down
4 changes: 2 additions & 2 deletions test/shopify-cli/theme/syncer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -573,7 +573,7 @@ def test_log_when_the_file_is_synced
@syncer.start_threads

# Assert a single synced message
@ctx.expects(:puts)
@ctx.expects(:error)
.with("12:30:59 {{green:Synced}} {{>}} {{blue:update #{file_path}}}").once

file.stubs(checksum: "initial")
Expand Down Expand Up @@ -637,7 +637,7 @@ def test_log_when_an_error_is_fixed
end

# Assert a single fix message
@ctx.expects(:puts).with("12:30:59 {{cyan:Fixed }} {{>}} {{blue:update sections/footer.liquid}}").once
@ctx.expects(:error).with("12:30:59 {{cyan:Fixed }} {{>}} {{blue:update sections/footer.liquid}}").once
file.stubs(checksum: "initial")
time_freeze do
@syncer.enqueue_updates([file])
Expand Down

0 comments on commit 79c988b

Please sign in to comment.