Skip to content

Commit

Permalink
(PDK-1096) Add puppet-dev flag to CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
Bryan Jen committed Aug 6, 2018
1 parent 37747fa commit ed4f67d
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 1 deletion.
6 changes: 6 additions & 0 deletions lib/pdk/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ def self.puppet_version_options(dsl)
dsl.option nil, 'pe-version', _('Puppet Enterprise version to run tests or validations against.'), argument: :required
end

def self.puppet_dev_option(dsl)
dsl.option nil,
'puppet-dev',
_('When specified, PDK will validate or test against the current Puppet source from github.com. To use this option, you must have network access to https://github.com.')
end

@base_cmd = Cri::Command.define do
name 'pdk'
usage _('pdk command [options]')
Expand Down
1 change: 1 addition & 0 deletions lib/pdk/cli/test/unit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module PDK::CLI
summary _('Run unit tests.')

PDK::CLI.puppet_version_options(self)
PDK::CLI.puppet_dev_option(self)
flag nil, :list, _('List all available unit test files.')
flag nil, :parallel, _('Run unit tests in parallel.')
flag :v, :verbose, _('More verbose --list output. Displays a list of examples in each unit test file.')
Expand Down
25 changes: 24 additions & 1 deletion lib/pdk/cli/util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,21 @@ def validate_puppet_version_opts(opts)
pe_ver_specs << '--pe-version option' if opts[:'pe-version']
pe_ver_specs << 'PDK_PE_VERSION environment variable' if ENV['PDK_PE_VERSION'] && !ENV['PDK_PE_VERSION'].empty?

puppet_dev_specs = []
puppet_dev_specs << '--puppet-dev flag' if opts[:'puppet-dev']
puppet_dev_specs << 'PDK_PUPPET_DEV environment variable' if ENV['PDK_PUPPET_DEV'] && !ENV['PDK_PUPPET_DEV'].empty?

puppet_dev_specs.each do |pup_dev_spec|
[puppet_ver_specs, pe_ver_specs].each do |offending|
next if offending.empty?

raise PDK::CLI::ExitWithError, _('You cannot specify a %{first} and %{second} at the same time') % {
first: pup_dev_spec,
second: offending.first,
}
end
end

puppet_ver_specs.each do |pup_ver_spec|
next if pe_ver_specs.empty?

Expand All @@ -143,7 +158,15 @@ def validate_puppet_version_opts(opts)
}
end

if puppet_ver_specs.size == 2
if puppet_dev_specs.size == 2
warning_str = 'Puppet dev flag from command line: "--puppet-dev" '
warning_str += 'overrides value from environment: "PDK_PUPPET_DEV=true". You should not specify both.'

PDK.logger.warn(_(warning_str) % {
pup_ver_opt: opts[:'puppet-dev'],
pup_ver_env: ENV['PDK_PUPPET_DEV'],
})
elsif puppet_ver_specs.size == 2
warning_str = 'Puppet version option from command line: "--puppet-version=%{pup_ver_opt}" '
warning_str += 'overrides value from environment: "PDK_PUPPET_VERSION=%{pup_ver_env}". You should not specify both.'

Expand Down
1 change: 1 addition & 0 deletions lib/pdk/cli/validate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ module PDK::CLI
)

PDK::CLI.puppet_version_options(self)
PDK::CLI.puppet_dev_option(self)
flag nil, :list, _('List all available validators.')
flag :a, 'auto-correct', _('Automatically correct problems where possible.')
flag nil, :parallel, _('Run validations in parallel.')
Expand Down
28 changes: 28 additions & 0 deletions spec/unit/pdk/cli/validate_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -221,4 +221,32 @@
}.to exit_zero
end
end

context 'with --puppet-dev' do
it 'activates resolved puppet version' do
expect {
PDK::CLI.run(['validate', '--puppet-dev'])
}.to exit_zero
end
end

context 'with both --puppet-version and --puppet-dev' do
it 'exits with an error' do
expect(logger).to receive(:error).with(a_string_matching(%r{cannot specify.*--puppet-dev.*and.*--puppet-version}i))

expect {
PDK::CLI.run(%w[validate --puppet-version 4.10.10 --puppet-dev])
}.to exit_nonzero
end
end

context 'with both --pe-version and --puppet-dev' do
it 'exits with an error' do
expect(logger).to receive(:error).with(a_string_matching(%r{cannot specify.*--puppet-dev.*and.*--pe-version}i))

expect {
PDK::CLI.run(%w[validate --pe-version 2018.1 --puppet-dev])
}.to exit_nonzero
end
end
end

0 comments on commit ed4f67d

Please sign in to comment.