diff --git a/lib/plugins/inspec-init/lib/inspec-init/cli_plugin.rb b/lib/plugins/inspec-init/lib/inspec-init/cli_plugin.rb index e07a013bc..59433cbdd 100644 --- a/lib/plugins/inspec-init/lib/inspec-init/cli_plugin.rb +++ b/lib/plugins/inspec-init/lib/inspec-init/cli_plugin.rb @@ -12,6 +12,7 @@ module InspecPlugins desc 'PLUGIN_NAME [options]', 'Generates an InSpec plugin, which can extend the functionality of InSpec itself.' # General options option :prompt, type: :boolean, default: true, desc: 'Interactively prompt for information to put in your generated plugin.' + option :detail, type: :string, default: 'full', desc: "How detailed of a plugin to generate. 'full' is a normal full gem with tests; 'core' has tests but no gemspec; 'test-fixture' is stripped down for a test fixture." # Templating vars option :author_email, type: :string, default: 'you@example.com', desc: 'Author Email for gemspec' @@ -65,6 +66,7 @@ module InspecPlugins templates_path: TEMPLATES_PATH, overwrite: options[:overwrite], file_rename_map: rename_map, + skip_files: make_skip_list, } renderer = InspecPlugins::Init::Renderer.new(ui, render_opts) @@ -196,6 +198,40 @@ module InspecPlugins '"Other" license selected at plugin generation time - please insert your license here.' end end + + def make_skip_list + case options[:detail] + when 'full' + [] + when 'core' + [ + 'Gemfile', + 'inspec-plugin-template.gemspec', + 'LICENSE', + 'Rakefile', + ] + when 'test-fixture' + [ + 'Gemfile', + 'inspec-plugin-template.gemspec', + 'LICENSE', + 'Rakefile', + File.join('test','fixtures','README.md'), + File.join('test','fixtures'), + File.join('test','functional','inspec_plugin_template_test.rb'), + File.join('test','functional','README.md'), + File.join('test','unit','cli_args_test.rb'), + File.join('test','unit','plugin_def_test.rb'), + File.join('test','unit','README.md'), + File.join('test','unit'), + File.join('test','helper.rb'), + File.join('test'), + ] + else + ui.error "Unrecognized value for 'detail': #{options[:detail]} - expected one of full, core, test-fixture" + ui.exit(:usage_error) + end + end end end end diff --git a/lib/plugins/inspec-init/lib/inspec-init/renderer.rb b/lib/plugins/inspec-init/lib/inspec-init/renderer.rb index 2fe88d492..73e1065f7 100644 --- a/lib/plugins/inspec-init/lib/inspec-init/renderer.rb +++ b/lib/plugins/inspec-init/lib/inspec-init/renderer.rb @@ -9,12 +9,13 @@ module InspecPlugins # 2. read content in erb # 3. write to destination path - attr_reader :file_rename_map, :overwrite_mode, :templates_path, :ui + attr_reader :file_rename_map, :overwrite_mode, :skip_files, :templates_path, :ui def initialize(cli_ui, options = {}) @ui = cli_ui @overwrite_mode = options[:overwrite] @templates_path ||= options[:templates_path] @file_rename_map = options[:file_rename_map] || {} + @skip_files = options[:skip_files] || [] end # rubocop: disable Metrics/AbcSize @@ -52,6 +53,7 @@ module InspecPlugins # iterate over files and write to full_destination_path Dir.glob(template_glob) do |source_file| relative_destination_item_path = Pathname.new(source_file).relative_path_from(Pathname.new(source_dir)).to_s + next if skip_files.include? relative_destination_item_path relative_destination_item_path = file_rename_map[relative_destination_item_path] || relative_destination_item_path full_destination_item_path = Pathname.new(full_destination_path).join(relative_destination_item_path) if File.directory?(source_file)