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

(PDK-722) Remove prompt to continue from start of convert #378

Merged
merged 1 commit into from
Dec 6, 2017
Merged
Show file tree
Hide file tree
Changes from all 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: 0 additions & 5 deletions lib/pdk/cli/convert.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,6 @@ module PDK::CLI
raise PDK::CLI::ExitWithError, _('You can not specify --noop and --force when converting a module')
end

unless opts[:noop] || opts[:force]
PDK.logger.info _('Module conversion is a potentially destructive action. Please ensure that you have committed it to a version control system or have a backup before continuing.')
exit 0 unless PDK::CLI::Util.prompt_for_yes(_('Do you want to proceed with conversion?'))
end

PDK::Module::Convert.invoke(opts)
end
end
Expand Down
6 changes: 5 additions & 1 deletion lib/pdk/module/convert.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ def self.invoke(options)
return if options[:noop]

unless options[:force]
PDK.logger.info _('Please review the changes above before continuing.')
PDK.logger.info _(
'Module conversion is a potentially destructive action. ' \
'Please ensure that you have committed your module to a version control ' \
'system or have a backup, and review the changes above before continuing.',
)
continue = PDK::CLI::Util.prompt_for_yes(_('Do you want to continue and make these changes to your module?'))
return unless continue
end
Expand Down
48 changes: 1 addition & 47 deletions spec/unit/pdk/cli/convert_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

describe 'PDK::CLI convert' do
let(:help_text) { a_string_matching(%r{^USAGE\s+pdk convert}m) }
let(:backup_warning) { a_string_matching(%r{backup before continuing}i) }

context 'when not run from inside a module' do
before(:each) do
Expand All @@ -26,43 +25,14 @@
end

context 'and provided no flags' do
before(:each) do
allow(logger).to receive(:info).with(backup_warning)
allow(PDK::CLI::Util).to receive(:prompt_for_yes).with(a_string_matching(%r{Do you want to proceed with conversion?}i)).and_return(true)
end

it 'asks the user if they want to continue' do
expect(logger).to receive(:info).with(backup_warning)
expect(PDK::CLI::Util).to receive(:prompt_for_yes).with(a_string_matching(%r{Do you want to proceed with conversion?}i)).and_return(true)
allow(PDK::Module::Convert).to receive(:invoke).with(any_args).and_return(0)

PDK::CLI.run(%w[convert])
end

it 'exits cleanly if the user chooses not to continue' do
allow(PDK::CLI::Util).to receive(:prompt_for_yes).with(a_string_matching(%r{Do you want to proceed with conversion?}i)).and_return(false)
expect(PDK::Module::Convert).not_to receive(:invoke)

expect {
PDK::CLI.run(['convert'])
}.to raise_error(SystemExit) { |error|
expect(error.status).to eq(0)
}
end

it 'invokes the converter with the default template if the user chooses to continue' do
it 'invokes the converter with the default template' do
expect(PDK::Module::Convert).to receive(:invoke).with(:'template-url' => PDK::Util.default_template_url)

PDK::CLI.run(['convert'])
end
end

context 'and the --template-url option has been passed' do
before(:each) do
allow(logger).to receive(:info).with(backup_warning)
allow(PDK::CLI::Util).to receive(:prompt_for_yes).with(a_string_matching(%r{Do you want to proceed with conversion?}i)).and_return(true)
end

it 'invokes the converter with the user supplied template' do
expect(PDK::Module::Convert).to receive(:invoke).with(:'template-url' => 'https://my/template')

Expand All @@ -71,14 +41,6 @@
end

context 'and the --noop flag has been passed' do
it 'does not prompt the user before invoking the converter' do
expect(logger).not_to receive(:info).with(backup_warning)
expect(PDK::CLI::Util).not_to receive(:prompt_for_yes)
allow(PDK::Module::Convert).to receive(:invoke).with(any_args)

PDK::CLI.run(['convert', '--noop'])
end

it 'passes the noop option through to the converter' do
expect(PDK::Module::Convert).to receive(:invoke).with(:noop => true, :'template-url' => anything)

Expand All @@ -87,14 +49,6 @@
end

context 'and the --force flag has been passed' do
it 'does not prompt the user before invoking the converter' do
expect(logger).not_to receive(:info).with(backup_warning)
expect(PDK::CLI::Util).not_to receive(:prompt_for_yes)
allow(PDK::Module::Convert).to receive(:invoke).with(any_args)

PDK::CLI.run(['convert', '--force'])
end

it 'passes the force option through to the converter' do
expect(PDK::Module::Convert).to receive(:invoke).with(:force => true, :'template-url' => anything)

Expand Down