Class: InspecPlugins::Init::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/plugins/inspec-init/lib/inspec-init/cli.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.valid_profile_platformsObject

——————————————————————-#

inspec init profile

——————————————————————-#



14
15
16
17
18
# File 'lib/plugins/inspec-init/lib/inspec-init/cli.rb', line 14

def self.valid_profile_platforms
  # Look in the 'template/profiles' directory and detect which platforms are available.
  profile_templates_dir = File.join(File.dirname(__FILE__), 'templates', 'profiles')
  Dir.glob(File.join(profile_templates_dir, '*')).select { |p| File.directory?(p) }.map { |d| File.basename(d) }
end

Instance Method Details

#profile(new_profile_name) ⇒ Object



31
32
33
34
35
36
37
38
39
# File 'lib/plugins/inspec-init/lib/inspec-init/cli.rb', line 31

def profile(new_profile_name)
  unless valid_profile_platforms.include?(options[:platform])
    puts "Unable to generate profile: No template available for platform '#{options[:platform]}' (expected one of: #{valid_profile_platforms.join(', ')})"
    exit 1
  end
  template_path = File.join('profiles', options[:platform])
  renderer = InspecPlugins::Init::Renderer.new(self, options)
  renderer.render_with_values(template_path, name: new_profile_name)
end