Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove prompt from CLI2 #4175

Merged
merged 5 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/tiny-lobsters-shout.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@shopify/cli-kit': patch
---

Remove unnecessary prompt from CLI2
Original file line number Diff line number Diff line change
Expand Up @@ -23,42 +23,7 @@ def self.reporting_enabled?
end

def self.check_or_prompt_report_automatically(source: :usage, prompt: true, context: ShopifyCLI::Context.new)
return false if ShopifyCLI::Environment.development? || ShopifyCLI::Environment.test?

# If the terminal is not interactive we can't prompt the user.
return false unless ShopifyCLI::Environment.interactive?

if reporting_prompted?
reporting_enabled?
elsif prompt
prompt_user(context: context, source: source)
else
false
end
end

def self.prompt_user(context:, source:)
enable_automatic_tracking = CLI::UI::Prompt.ask(
context.message("core.analytics.enable_prompt.#{source}.question")
) do |handler|
handler.option(context.message("core.analytics.enable_prompt.#{source}.yes")) { |_| true }
handler.option(context.message("core.analytics.enable_prompt.#{source}.no")) { |_| false }
end

ShopifyCLI::Config.set(
Constants::Config::Sections::Analytics::NAME,
Constants::Config::Sections::Analytics::Fields::ENABLED,
enable_automatic_tracking
)

message = if enable_automatic_tracking
context.message("core.reporting.turned_on_message")
else
context.message("core.reporting.turned_off_message", ShopifyCLI::TOOL_NAME)
end
context.puts(message)

enable_automatic_tracking
return false
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -57,55 +57,5 @@ def test_check_or_prompt_report_automatically_returns_false_when_the_environment
refute got
end

def test_check_or_prompt_report_automatically_returns_true_when_the_user_was_already_prompted_and_they_enabled_it
# Given
ShopifyCLI::Environment.expects(:test?).returns(false)
ShopifyCLI::Environment.expects(:development?).returns(false)
ShopifyCLI::Environment.expects(:interactive?).returns(true)
ShopifyCLI::Config
.expects(:get_section)
.with(Constants::Config::Sections::Analytics::NAME)
.returns({ Constants::Config::Sections::Analytics::Fields::ENABLED => true })
ShopifyCLI::Config
.expects(:get_bool)
.with(
Constants::Config::Sections::Analytics::NAME,
Constants::Config::Sections::Analytics::Fields::ENABLED,
default: false
)
.returns(true)

# When
got = ReportingConfigurationController.check_or_prompt_report_automatically(context: @context)

# Then
assert got
end

def test_check_or_prompt_report_automatically_stores_and_returns_the_value_selected_by_the_user
# Given
ShopifyCLI::Environment.expects(:test?).returns(false)
ShopifyCLI::Environment.expects(:development?).returns(false)
ShopifyCLI::Environment.expects(:interactive?).returns(true)
ShopifyCLI::Config
.expects(:get_section)
.with(Constants::Config::Sections::Analytics::NAME)
.returns({})

ShopifyCLI::Config
.expects(:set)
.with(
Constants::Config::Sections::Analytics::NAME,
Constants::Config::Sections::Analytics::Fields::ENABLED,
false
)
CLI::UI::Prompt.expects(:ask).returns(false)

# When
got = ReportingConfigurationController.check_or_prompt_report_automatically(context: @context)

# Then
refute got
end
end
end
Loading