Class: InspecPlugins::Init::CLI
- Inherits:
- 
      Object
      
        - Object
- InspecPlugins::Init::CLI
 
- Defined in:
- lib/plugins/inspec-init/lib/inspec-init/cli.rb,
 lib/plugins/inspec-init/lib/inspec-init/cli_plugin.rb,
 lib/plugins/inspec-init/lib/inspec-init/cli_profile.rb
Constant Summary collapse
- TEMPLATES_PATH =
- File.(File.join(File.dirname(__FILE__), "..", "..", "templates")) 
Class Method Summary collapse
- 
  
    
      .valid_profile_platforms  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    ——————————————————————-# inspec init profile ——————————————————————-#. 
Instance Method Summary collapse
Class Method Details
.valid_profile_platforms ⇒ Object
——————————————————————-#
inspec init profile
——————————————————————-#
| 10 11 12 13 14 | # File 'lib/plugins/inspec-init/lib/inspec-init/cli_profile.rb', line 10 def self.valid_profile_platforms # Look in the 'template/profiles' directory and detect which platforms are available. profile_templates_dir = File.join(TEMPLATES_PATH, "profiles") Dir.glob(File.join(profile_templates_dir, "*")).select { |p| File.directory?(p) }.map { |d| File.basename(d) } end | 
Instance Method Details
#plugin(plugin_name) ⇒ Object
| 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | # File 'lib/plugins/inspec-init/lib/inspec-init/cli_plugin.rb', line 28 def plugin(plugin_name) plugin_type = determine_plugin_type(plugin_name) snake_case = plugin_name.tr("-", "_") template_vars = { name: plugin_name, plugin_name: plugin_name, snake_case: snake_case, }.merge(plugin_vars_from_opts) template_path = File.join("plugins", plugin_type + "-plugin-template") render_opts = { templates_path: TEMPLATES_PATH, overwrite: [:overwrite], file_rename_map: make_rename_map(plugin_type, plugin_name, snake_case), skip_files: make_skip_list(template_vars["hooks"].keys), } renderer = InspecPlugins::Init::Renderer.new(ui, render_opts) renderer.render_with_values(template_path, plugin_type + " plugin", template_vars) end | 
#profile(new_profile_name) ⇒ Object
| 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | # File 'lib/plugins/inspec-init/lib/inspec-init/cli_profile.rb', line 27 def profile(new_profile_name) unless valid_profile_platforms.include?([:platform]) ui.error "Unable to generate profile: No template available for platform '#{[:platform]}' (expected one of: #{valid_profile_platforms.join(", ")})" ui.exit(:usage_error) end template_path = File.join("profiles", [:platform]) render_opts = { templates_path: TEMPLATES_PATH, overwrite: [:overwrite], } renderer = InspecPlugins::Init::Renderer.new(ui, render_opts) vars = { name: new_profile_name, } renderer.render_with_values(template_path, "profile", vars) end |