diff --git a/lib/pdk/generators/module.rb b/lib/pdk/generators/module.rb index e88cc7f6a..d94058498 100644 --- a/lib/pdk/generators/module.rb +++ b/lib/pdk/generators/module.rb @@ -171,6 +171,67 @@ def self.module_interview(metadata, opts = {}) required: true, default: metadata.data['license'], }, + { + name: 'operatingsystem_support', + question: _('What operating systems does this module support?'), + help: _('Use the up and down keys to move between the choices, space to select and enter to continue.'), + required: true, + choices: { + 'CentOS' => { + 'operatingsystem' => 'CentOS', + 'operatingsystemrelease' => ['7'], + }, + 'Debian' => { + 'operatingsystem' => 'Debian', + 'operatingsystemrelease' => ['8'], + }, + 'Fedora' => { + 'operatingsystem' => 'Fedora', + 'operatingsystemrelease' => ['25'], + }, + 'Oracle Linux' => { + 'operatingsystem' => 'OracleLinux', + 'operatingsystemrelease' => ['7'], + }, + 'OSX' => { + 'operatingsystem' => 'Darwin', + 'operatingsystemrelease' => ['16'], + }, + 'RedHat' => { + 'operatingsystem' => 'RedHat', + 'operatingsystemrelease' => ['7'], + }, + 'Scientific' => { + 'operatingsystem' => 'Scientific', + 'operatingsystemrelease' => ['7'], + }, + 'SLES' => { + 'operatingsystem' => 'SLES', + 'operatingsystemrelease' => ['12'], + }, + 'Solaris' => { + 'operatingsystem' => 'Solaris', + 'operatingsystemrelease' => '11', + }, + 'Ubuntu' => { + 'operatingsystem' => 'Ubuntu', + 'operatingsystemrelease' => ['16.04'], + }, + 'Windows Server 2008 R2' => { + 'operatingsystem' => 'windows', + 'operatingsystemrelease' => ['2008 R2'], + }, + 'Windows Server 2012 R2' => { + 'operatingsystem' => 'windows', + 'operatingsystemrelease' => ['2012 R2'], + }, + 'Windows 10' => { + 'operatingsystem' => 'windows', + 'operatingsystemrelease' => ['10'], + }, + }, + default: [2, 6, 10, 12], + }, { name: 'summary', question: _('Please summarize the purpose of this module in a single sentence.'), @@ -225,6 +286,18 @@ def self.module_interview(metadata, opts = {}) forge_username = answers['name'] answers['name'] = "#{answers['name']}-#{opts[:name]}" answers['license'] = opts[:license] if opts.key?(:license) + operating_systems = answers['operatingsystem_support'].dup + answers['operatingsystem_support'] = operating_systems.inject([]) do |result, os_hash| + existing = result.select { |r| r['operatingsystem'] == os_hash['operatingsystem'] } + + if existing.empty? + result << os_hash + else + existing.first['operatingsystemrelease'].concat(os_hash['operatingsystemrelease']) + end + + result + end metadata.update!(answers) puts '-' * 40 diff --git a/spec/unit/pdk/generate/module_spec.rb b/spec/unit/pdk/generate/module_spec.rb index ae2d74403..0f0762524 100644 --- a/spec/unit/pdk/generate/module_spec.rb +++ b/spec/unit/pdk/generate/module_spec.rb @@ -244,6 +244,7 @@ '2.2.0', 'William Hopper', 'Apache-2.0', + '', 'A simple module to do some stuff.', 'github.com/whopper/bar', 'forge.puppet.com/whopper/bar', @@ -253,17 +254,35 @@ end it 'populates the Metadata object based on user input' do - allow($stdout).to receive(:puts).with(a_string_matching(%r{8 quick questions}m)) + allow($stdout).to receive(:puts).with(a_string_matching(%r{9 quick questions}m)) expect(interview_metadata).to include( - 'name' => 'foo-bar', - 'version' => '2.2.0', - 'author' => 'William Hopper', - 'license' => 'Apache-2.0', - 'summary' => 'A simple module to do some stuff.', - 'source' => 'github.com/whopper/bar', - 'project_page' => 'forge.puppet.com/whopper/bar', - 'issues_url' => 'tickets.foo.com/whopper/bar', + 'name' => 'foo-bar', + 'version' => '2.2.0', + 'author' => 'William Hopper', + 'license' => 'Apache-2.0', + 'summary' => 'A simple module to do some stuff.', + 'source' => 'github.com/whopper/bar', + 'project_page' => 'forge.puppet.com/whopper/bar', + 'issues_url' => 'tickets.foo.com/whopper/bar', + 'operatingsystem_support' => [ + { + 'operatingsystem' => 'Debian', + 'operatingsystemrelease' => ['8'], + }, + { + 'operatingsystem' => 'RedHat', + 'operatingsystemrelease' => ['7'], + }, + { + 'operatingsystem' => 'Ubuntu', + 'operatingsystemrelease' => ['16.04'], + }, + { + 'operatingsystem' => 'windows', + 'operatingsystemrelease' => ['2012 R2'], + } + ], ) end @@ -303,11 +322,12 @@ '', '', '', + '', ] end it 'populates the interview question defaults with existing metadata values' do - allow($stdout).to receive(:puts).with(a_string_matching(%r{8 quick questions})) + allow($stdout).to receive(:puts).with(a_string_matching(%r{9 quick questions})) expect(interview_metadata).to include( 'name' => 'defaultauthor-bar', @@ -341,6 +361,7 @@ 'foo', '2.2.0', 'William Hopper', + '', 'A simple module to do some stuff.', 'github.com/whopper/bar', 'forge.puppet.com/whopper/bar', @@ -350,7 +371,7 @@ end it 'populates the Metadata object based on user input' do - allow($stdout).to receive(:puts).with(a_string_matching(%r{7 quick questions}m)) + allow($stdout).to receive(:puts).with(a_string_matching(%r{8 quick questions}m)) expect(interview_metadata).to include( 'name' => 'foo-bar', @@ -386,7 +407,7 @@ it 'exits cleanly' do allow(logger).to receive(:info).with(a_string_matching(%r{interview cancelled}i)) - allow($stdout).to receive(:puts).with(a_string_matching(%r{8 quick questions}m)) + allow($stdout).to receive(:puts).with(a_string_matching(%r{9 quick questions}m)) expect { interview_metadata }.to raise_error(SystemExit) { |error| expect(error.status).to eq(0) @@ -403,6 +424,7 @@ '2.2.0', 'William Hopper', 'Apache-2.0', + '', 'A simple module to do some stuff.', 'github.com/whopper/bar', 'forge.puppet.com/whopper/bar', @@ -413,7 +435,7 @@ it 'exits cleanly' do allow(logger).to receive(:info).with(a_string_matching(%r{module not generated}i)) - allow($stdout).to receive(:puts).with(a_string_matching(%r{8 quick questions}m)) + allow($stdout).to receive(:puts).with(a_string_matching(%r{9 quick questions}m)) expect { interview_metadata }.to raise_error(SystemExit) { |error| expect(error.status).to eq(0) @@ -430,6 +452,7 @@ '2.2.0', 'William Hopper', 'Apache-2.0', + '', 'A simple module to do some stuff.', 'github.com/whopper/bar', 'forge.puppet.com/whopper/bar', @@ -455,6 +478,63 @@ ) end end + + context 'when the user selects operating systems' do + include_context 'allow summary to be printed to stdout' + + let(:responses) do + [ + 'foo', + '2.2.0', + 'William Hopper', + 'Apache-2.0', + "\e[A 1 ", # \e[A == up arrow + 'A simple module to do some stuff.', + 'github.com/whopper/bar', + 'forge.puppet.com/whopper/bar', + 'tickets.foo.com/whopper/bar', + 'yes', + ] + end + + it 'includes the modified operatingsystem_support value in the metadata' do + allow($stdout).to receive(:puts).and_call_original + expect { interview_metadata }.not_to raise_error + + expect(interview_metadata).to include( + 'name' => 'foo-bar', + 'version' => '2.2.0', + 'author' => 'William Hopper', + 'license' => 'Apache-2.0', + 'summary' => 'A simple module to do some stuff.', + 'source' => 'github.com/whopper/bar', + 'project_page' => 'forge.puppet.com/whopper/bar', + 'issues_url' => 'tickets.foo.com/whopper/bar', + 'operatingsystem_support' => [ + { + 'operatingsystem' => 'Debian', + 'operatingsystemrelease' => ['8'], + }, + { + 'operatingsystem' => 'RedHat', + 'operatingsystemrelease' => ['7'], + }, + { + 'operatingsystem' => 'Ubuntu', + 'operatingsystemrelease' => ['16.04'], + }, + { + 'operatingsystem' => 'windows', + 'operatingsystemrelease' => ['2012 R2', '2008 R2'], + }, + { + 'operatingsystem' => 'CentOS', + 'operatingsystemrelease' => ['7'], + }, + ], + ) + end + end end describe '.prepare_metadata' do