class Retrospec::Puppet::Generators::TaskGenerator

Constants

EXT_TYPES

Public Class Methods

new(module_path, spec_object = {}) click to toggle source

retrospec will initilalize this class so its up to you to set any additional variables you need to get the job done.

# File lib/retrospec/plugins/v1/plugin/generators/task_generator.rb, line 18
def initialize(module_path, spec_object = {})
  super
  @plural_name = 'tasks'
  @singular_name = 'task'
end
run_cli(global_opts, args = ARGV) click to toggle source

used to display subcommand options to the cli the global options are passed in for your usage optimist.rubyforge.org all options here are available in the config passed into config object returns the parameters

# File lib/retrospec/plugins/v1/plugin/generators/task_generator.rb, line 85
        def self.run_cli(global_opts, args = ARGV)
          task_types = %w(bash generic ruby python node powershell)
          task_type  = global_opts['plugins::puppet::default_task_type'] || 'bash'
          sub_command_opts = Optimist.options(args) do
            banner <<-EOS
Creates a new puppet bolt task for your module

Example: retrospec puppet new_task -n reboot -p "name, ttl, message"

            EOS
            opt :name, 'The name of the task you wish to create', :type => :string, :required => true, :short => '-n'
            opt :task_params, 'The task parameter names separated by commas', :short => '-p', :type => :string, :required => false, default: 'name'
            opt :task_type, "The task type of the task (#{task_types.join(', ')})", :type => :string, :required => false, :short => '-t',
                                                                                    :default => task_type
          end
          unless sub_command_opts[:name]
            Optimist.educate
            exit 1
          end
          plugin_data = global_opts.merge(sub_command_opts)
          plugin_data
        end

Public Instance Methods

enable_beaker_tasks?() click to toggle source
# File lib/retrospec/plugins/v1/plugin/generators/task_generator.rb, line 61
def enable_beaker_tasks?
  false
end
generate_task_files() click to toggle source
# File lib/retrospec/plugins/v1/plugin/generators/task_generator.rb, line 65
def generate_task_files
  context.task_type = task_type
  context.shebang = shebang
  context.task_params_output = task_params_output
  context.task_params = task_params
  parameter_template = File.join(template_dir, 'task_parameters.json.retrospec.erb')
  task_template = Dir.glob(File.join(template_dir, 'types', task_type, '*')).first
  unless task_template
    task_template = Dir.glob(File.join(template_dir, 'types', 'task.retrospec.erb')).first
  end
  safe_create_template_file(task_filepath, task_template, context)
  safe_create_template_file(task_params_filepath, parameter_template, context)
  [task_filepath, task_params_filepath]
end
run() click to toggle source
# File lib/retrospec/plugins/v1/plugin/generators/task_generator.rb, line 46
def run
  files = []
  files << generate_task_files
  files
end
shebang() click to toggle source
# File lib/retrospec/plugins/v1/plugin/generators/task_generator.rb, line 24
def shebang
  "#!/usr/bin/env #{task_type}"
end
task_filepath() click to toggle source
# File lib/retrospec/plugins/v1/plugin/generators/task_generator.rb, line 52
def task_filepath
  ext = EXT_TYPES.fetch(task_type, task_type)
  File.join(module_path, 'tasks', "#{item_name}.#{ext}")
end
task_params() click to toggle source
# File lib/retrospec/plugins/v1/plugin/generators/task_generator.rb, line 28
def task_params
  config_data[:task_params].gsub(/\s/, '').split(',')
end
task_params_filepath() click to toggle source
# File lib/retrospec/plugins/v1/plugin/generators/task_generator.rb, line 57
def task_params_filepath
  File.join(module_path, 'tasks', "#{item_name}.json")
end
task_params_output() click to toggle source
# File lib/retrospec/plugins/v1/plugin/generators/task_generator.rb, line 32
def task_params_output
  params = {}
  task_params.each_with_object({}) do |item, obj|
    obj['description'] = "The description of the #{item} parameter"
    obj['type'] = 'String'
    params[item] = obj
  end
  params
end
task_type() click to toggle source
# File lib/retrospec/plugins/v1/plugin/generators/task_generator.rb, line 42
def task_type
  config_data[:task_type]
end