Skip to content

Commit

Permalink
(PDK-550) Add --full-interview flag to convert command
Browse files Browse the repository at this point in the history
Also adds CLI error handling of conflicting options and unit tests.
  • Loading branch information
bmjen committed Jan 23, 2018
1 parent 09cac01 commit 5e2c202
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 0 deletions.
11 changes: 11 additions & 0 deletions lib/pdk/cli/convert.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module PDK::CLI

PDK::CLI.template_url_option(self)
PDK::CLI.skip_interview_option(self)
PDK::CLI.full_interview_option(self)
flag nil, :noop, _('Do not convert the module, just output what would be done.')
flag nil, :force, _('Convert the module automatically, with no prompts.')

Expand All @@ -24,6 +25,16 @@ module PDK::CLI
raise PDK::CLI::ExitWithError, _('You can not specify --noop and --force when converting a module')
end

if opts[:'skip-interview'] && opts[:'full-interview']
PDK.logger.info _('Ignoring --full-interview and continuing with --skip-interview.')
opts[:'full-interview'] = false
end

if opts[:force] && opts[:'full-interview']
PDK.logger.info _('Ignoring --full-interview and continuing with --force.')
opts[:'full-interview'] = false
end

PDK::Module::Convert.invoke(opts)
end
end
Expand Down
5 changes: 5 additions & 0 deletions lib/pdk/cli/new/module.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ module PDK::CLI
module_name = args[0]
target_dir = args[1]

if opts[:'skip-interview'] && opts[:'full-interview']
PDK.logger.info _('Ignoring --full-interview and continuing with --skip-interview.')
opts[:'full-interview'] = false
end

unless module_name.nil? || module_name.empty?
module_name_parts = module_name.split('-', 2)
if module_name_parts.size > 1
Expand Down
34 changes: 34 additions & 0 deletions spec/unit/pdk/cli/convert_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,39 @@
}
end
end

context 'and the --skip-interview flag has been passed' do
it 'passes the skip-interview option through to the converter' do
expect(PDK::Module::Convert).to receive(:invoke).with(:'skip-interview' => true, :'template-url' => anything)

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

context 'and the --full-interview flag has been passed' do
it 'passes the full-interview option through to the converter' do
expect(PDK::Module::Convert).to receive(:invoke).with(:'full-interview' => true, :'template-url' => anything)

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

context 'and the --skip-interview and --full-interview flags have been passed' do
it 'ignores full-interview and continues with a log message' do
expect(logger).to receive(:info).with(a_string_matching(%r{Ignoring --full-interview and continuing with --skip-interview.}i))
expect(PDK::Module::Convert).to receive(:invoke).with(:'skip-interview' => true, :'full-interview' => false, :'template-url' => anything)

PDK::CLI.run(['convert', '--skip-interview', '--full-interview'])
end
end

context 'and the --force and --full-interview flags have been passed' do
it 'ignores full-interview and continues with a log message' do
expect(logger).to receive(:info).with(a_string_matching(%r{Ignoring --full-interview and continuing with --force.}i))
expect(PDK::Module::Convert).to receive(:invoke).with(:force => true, :'full-interview' => false, :'template-url' => anything)

PDK::CLI.run(['convert', '--force', '--full-interview'])
end
end
end
end
9 changes: 9 additions & 0 deletions spec/unit/pdk/cli/new/module_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,15 @@
PDK::CLI.run(['new', 'module', '--full-interview', module_name])
end
end

context 'and the --skip-interview and --full-interview flags have been passed' do
it 'ignores full-interview and continues with a log message' do
expect(logger).to receive(:info).with(a_string_matching(%r{Ignoring --full-interview and continuing with --skip-interview.}i))
expect(PDK::Generate::Module).to receive(:invoke).with(hash_including(:'skip-interview' => true, :'full-interview' => false))

PDK::CLI.run(['new', 'module', '--skip-interview', '--full-interview'])
end
end
end

context 'when passed a module name with a forge user' do
Expand Down

0 comments on commit 5e2c202

Please sign in to comment.