Class: Comfy::CommandExecutioner

Inherits:
Thor
  • Object
show all
Defined in:
lib/comfy/command_executioner.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.available_distributionsHash

Method listing available distributions from template directory.

Returns:

  • (Hash)

    distributions structure containing info about them



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/comfy/command_executioner.rb', line 12

def available_distributions
  dir = Comfy::TEMPLATE_DIR
  return {} unless File.exist? dir

  description_files = Dir.glob(File.join(dir, '*', '*.description')).sort
  distributions  = {}
  description_files.each do |description_file|
    unless JSON::Validator.validate(Comfy::DESCRIPTION_SCHEMA_FILE, description_file)
      puts "Invalid distribution description #{description_file.inspect}, skipping."
      next
    end

    description = File.read(description_file)
    json = JSON.parse(description)
    name = json['name']
    distributions[name] = []
    json['versions'].each do |version|
      version_string = []
      version_string << version['major_version']
      version_string << version['minor_version']
      version_string << version['patch_version']

      distributions[name] << version_string.compact.join('.')
      distributions[name].sort!.reverse!
    end
  end

  distributions
end

Instance Method Details

#clean_cacheObject



92
93
94
95
96
# File 'lib/comfy/command_executioner.rb', line 92

def clean_cache
  dir = options['cache-dir']
  FileUtils.rm_r Dir.glob(File.join(dir, '*'))
  puts 'Cache cleaned successfully.'
end

#distributionsObject



63
64
65
66
67
# File 'lib/comfy/command_executioner.rb', line 63

def distributions
  self.class.available_distributions.each do |distribution, versions|
    versions.each { |version| $stdout.puts "#{distribution} #{version}" }
  end
end

#exportObject



75
76
77
78
79
80
81
82
83
# File 'lib/comfy/command_executioner.rb', line 75

def export
  dir = options['destination']
  FileUtils.mkdir_p dir unless File.exist?(dir) && File.directory?(dir)

  FileUtils.cp_r(File.join(Comfy::TEMPLATE_DIR, '.'), dir)
  $stdout.puts 'Template files copied successfully.'
  $stdout.puts "In order to use the new template directory change setting 'vm_templates_dir' in your configuration file to:"
  $stdout.puts "template-dir: #{File.absolute_path(dir)}"
end

#versionObject



58
59
60
# File 'lib/comfy/command_executioner.rb', line 58

def version
  $stdout.puts Comfy::VERSION
end