Class: Builderator::Tasks::CLI

Inherits:
Thor
  • Object
show all
Includes:
Thor::Actions
Defined in:
lib/builderator/tasks.rb

Overview

Top-level command line tasks

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Thor::Actions

#run_with_input, #template

Constructor Details

#initialize(*_) ⇒ CLI

Returns a new instance of CLI.



22
23
24
25
26
27
28
29
30
# File 'lib/builderator/tasks.rb', line 22

def initialize(*_)
  super

  Config.argv(options) ## Load command flags
  Config.load(File.join(ENV['HOME'], '.builderator/Buildfile'))
  Config.load(Util.relative_path('Buildfile').to_s)

  Config.compile
end

Class Method Details

.exit_on_failure? ⇒ Boolean

Returns:

  • (Boolean)


32
33
34
# File 'lib/builderator/tasks.rb', line 32

def self.exit_on_failure?
  true
end

Instance Method Details

#clean ⇒ Object



100
101
102
103
104
# File 'lib/builderator/tasks.rb', line 100

def clean
  invoke Tasks::Vagrant, :clean
  invoke Tasks::Berkshelf, :clean
  invoke Tasks::Vendor, :clean
end

#cleanup ⇒ Object

Globally enable/disable workspace cleanup



37
# File 'lib/builderator/tasks.rb', line 37

class_option 'cleanup', :type => :boolean, :default => true

#config(key = nil) ⇒ Object

Helper/utility commands



91
# File 'lib/builderator/tasks.rb', line 91

desc 'config', 'Print compiled configuration'

#ec2(*args) ⇒ Object



64
65
66
67
# File 'lib/builderator/tasks.rb', line 64

def ec2(*args)
  prepare
  invoke Tasks::Vagrant, :ec2, args, options
end

#generate(project = :default) ⇒ Object



126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# File 'lib/builderator/tasks.rb', line 126

def generate(project = :default)
  fail 'Please provide a valid build name with the `--build-name=VALUE` option!' unless Config.has?(:build_name)
  Config.generator.project.use(project)

  Config.generator.project.current.resource.each do |rname, resource|
    next if (options['ignore'] && options['ignore'].include?(rname.to_s)) ||
            resource.action == :ignore

    if (options['sync'] && options['sync'].include?(rname.to_s)) ||
       resource.action == :sync
      template resource.template, resource.path.first
      next
    end

    if (options['rm'] && options['rm'].include?(rname.to_s)) ||
       resource.action == :rm
      resource.path.each { |rm| remove_file rm }
      next
    end

    ## Create
    template resource.template, resource.path.first, :skip => true
  end
end

#image(profile = :default) ⇒ Object



72
73
74
75
76
77
# File 'lib/builderator/tasks.rb', line 72

def image(profile = :default)
  prepare

  invoke Tasks::Packer, :build, [profile], options
  invoke Tasks::Packer, :copy, [profile], options if options['copy']
end

#local(*args) ⇒ Object



58
59
60
61
# File 'lib/builderator/tasks.rb', line 58

def local(*args)
  prepare
  invoke Tasks::Vagrant, :local, args, options
end

#prepare ⇒ Object

Tasks common to local, ec2, and ami builds



42
# File 'lib/builderator/tasks.rb', line 42

desc 'prepare', 'Common preparation tasks for Vagrant and Packer'