Class: Awestruct::CLI::Invoker

Inherits:
Object
  • Object
show all
Defined in:
lib/awestruct/cli/invoker.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*options) ⇒ Invoker

Returns a new instance of Invoker.



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/awestruct/cli/invoker.rb', line 21

def initialize(*options)
  options = options.flatten
  if ( ( ! options.empty? ) && ( options.first === Awestruct::CLI::Options ) )
    @options = options.first
  else
    @options = Awestruct::CLI::Options.parse! options
  end
  @threads = []
  @profile = nil
  @success = true
end

Instance Attribute Details

#configObject (readonly)

Returns the value of attribute config.



17
18
19
# File 'lib/awestruct/cli/invoker.rb', line 17

def config
  @config
end

#optionsObject (readonly)

Returns the value of attribute options.



15
16
17
# File 'lib/awestruct/cli/invoker.rb', line 15

def options
  @options
end

#profileObject (readonly)

Returns the value of attribute profile.



18
19
20
# File 'lib/awestruct/cli/invoker.rb', line 18

def profile
  @profile
end

#successObject (readonly)

Returns the value of attribute success.



19
20
21
# File 'lib/awestruct/cli/invoker.rb', line 19

def success
  @success
end

Instance Method Details

#invoke!Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/awestruct/cli/invoker.rb', line 33

def invoke!
  load_profile() unless ( options.init )

  setup_config()

  invoke_init()      if ( options.init )
  invoke_script()    if ( options.script )
  invoke_force()     if ( options.force )
  invoke_generate()  if ( options.generate )
  invoke_deploy()    if ( options.deploy )
  invoke_server()    if ( options.server )
  invoke_auto()      if ( options.auto )

  wait_for_completion()
  success
end

#invoke_autoObject



110
111
112
# File 'lib/awestruct/cli/invoker.rb', line 110

def invoke_auto()
  Awestruct::CLI::Auto.new( config ).run
end

#invoke_deployObject



99
100
101
102
103
104
105
106
107
108
# File 'lib/awestruct/cli/invoker.rb', line 99

def invoke_deploy()
  deploy_config = profile[ 'deploy' ]

  if ( deploy_config.nil? )
    $stderr.puts "No configuration for 'deploy'"
    return
  end

  Awestruct::CLI::Deploy.new( config, deploy_config ).run
end

#invoke_forceObject



90
91
92
93
# File 'lib/awestruct/cli/invoker.rb', line 90

def invoke_force()
  FileUtils.rm_rf( File.join( config.dir, '.awestruct', 'dependency-cache' ) )
  FileUtils.rm_rf( config.output_dir )
end

#invoke_generateObject



95
96
97
# File 'lib/awestruct/cli/invoker.rb', line 95

def invoke_generate()
  @success = Awestruct::CLI::Generate.new( config, options.profile, options.base_url, 'http://localhost:4242', options.force ).run
end

#invoke_initObject



83
84
85
# File 'lib/awestruct/cli/invoker.rb', line 83

def invoke_init()
  Awestruct::CLI::Init.new( Dir.pwd, options.framework, options.scaffold ).run
end

#invoke_scriptObject



87
88
# File 'lib/awestruct/cli/invoker.rb', line 87

def invoke_script()
end

#invoke_serverObject



114
115
116
# File 'lib/awestruct/cli/invoker.rb', line 114

def invoke_server()
  run_in_thread( Awestruct::CLI::Server.new( './_site', options.bind_addr, options.port ) )
end

#load_profileObject



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/awestruct/cli/invoker.rb', line 50

def load_profile()
  site_yaml_file = File.join( Dir.pwd, '_config', 'site.yml' )
  if ( File.exist?( site_yaml_file ) )
    site_yaml      = YAML.load( File.read( site_yaml_file ) )
    if site_yaml
      profiles_data  = site_yaml['profiles'] || {}
      @profile = if profiles_data.nil?
        nil
      else
        if options.profile
          profiles_data[options.profile] || {}
        else
          # if no profile given, pick the first with deploy config
          options.profile, profile_data = profiles_data.select { |k,v| v && v['deploy'] }.first
          profile_data
        end
      end
    end
  end
 
  unless @profile
    $stderr.puts "Unable to locate profile: #{options.profile}" if options.profile
    options.profile = 'NONE'
    @profile = {}
  end 
  $stderr.puts "Using profile: #{options.profile}"
end

#setup_configObject



78
79
80
81
# File 'lib/awestruct/cli/invoker.rb', line 78

def setup_config()
  @config = Awestruct::Config.new( Dir.pwd )
  @config.track_dependencies = true if ( options.auto )
end