Class: Comfy::CommandExecutioner
- Inherits:
-
Thor
- Object
- Thor
- Comfy::CommandExecutioner
- Defined in:
- lib/comfy/command_executioner.rb
Class Method Summary collapse
-
.available_distributions ⇒ Hash
Method listing available distributions from template directory.
Instance Method Summary collapse
Class Method Details
.available_distributions ⇒ Hash
Method listing available distributions from template directory.
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_cache ⇒ Object
92 93 94 95 96 |
# File 'lib/comfy/command_executioner.rb', line 92 def clean_cache dir = ['cache-dir'] FileUtils.rm_r Dir.glob(File.join(dir, '*')) puts 'Cache cleaned successfully.' end |
#distributions ⇒ Object
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 |
#export ⇒ Object
75 76 77 78 79 80 81 82 83 |
# File 'lib/comfy/command_executioner.rb', line 75 def export dir = ['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 |