Class: Awestruct::CLI::Invoker
- Inherits:
-
Object
- Object
- Awestruct::CLI::Invoker
- Defined in:
- lib/awestruct/cli/invoker.rb
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#profile ⇒ Object
readonly
Returns the value of attribute profile.
-
#success ⇒ Object
readonly
Returns the value of attribute success.
Instance Method Summary collapse
-
#initialize(*options) ⇒ Invoker
constructor
A new instance of Invoker.
- #invoke! ⇒ Object
- #invoke_auto ⇒ Object
- #invoke_deploy ⇒ Object
- #invoke_force ⇒ Object
- #invoke_generate ⇒ Object
- #invoke_init ⇒ Object
- #invoke_script ⇒ Object
- #invoke_server ⇒ Object
- #load_profile ⇒ Object
- #setup_config ⇒ Object
Constructor Details
#initialize(*options) ⇒ Invoker
Returns a new instance of Invoker.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/awestruct/cli/invoker.rb', line 23 def initialize(*) = .flatten if ( ( ! .empty? ) && ( .first === Awestruct::CLI::Options ) ) @options = .first else @options = Awestruct::CLI::Options.parse! end @threads = [] @profile = nil @success = true logging_path = Pathname.new '.awestruct' logging_path.mkdir unless logging_path.exist? $LOG = Logger.new(Awestruct::AwestructLoggerMultiIO.new(@options.verbose, STDOUT, File.open('.awestruct/debug.log', 'w'))) $LOG.level = @options.verbose ? Logger::DEBUG : Logger::INFO $LOG.formatter = Awestruct::AwestructLogFormatter.new end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
19 20 21 |
# File 'lib/awestruct/cli/invoker.rb', line 19 def config @config end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
17 18 19 |
# File 'lib/awestruct/cli/invoker.rb', line 17 def @options end |
#profile ⇒ Object (readonly)
Returns the value of attribute profile.
20 21 22 |
# File 'lib/awestruct/cli/invoker.rb', line 20 def profile @profile end |
#success ⇒ Object (readonly)
Returns the value of attribute success.
21 22 23 |
# File 'lib/awestruct/cli/invoker.rb', line 21 def success @success end |
Instance Method Details
#invoke! ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/awestruct/cli/invoker.rb', line 40 def invoke! load_profile() unless ( .init ) setup_config() invoke_init() if ( .init ) invoke_script() if ( .script ) invoke_force() if ( .force ) invoke_generate() if ( .generate ) invoke_deploy() if ( .deploy ) invoke_server() if ( .server ) invoke_auto() if ( .auto ) wait_for_completion() success end |
#invoke_auto ⇒ Object
118 119 120 |
# File 'lib/awestruct/cli/invoker.rb', line 118 def invoke_auto() Awestruct::CLI::Auto.new( config ).run end |
#invoke_deploy ⇒ Object
107 108 109 110 111 112 113 114 115 116 |
# File 'lib/awestruct/cli/invoker.rb', line 107 def invoke_deploy() deploy_config = profile[ 'deploy' ] if ( deploy_config.nil? ) $LOG.error "No configuration for 'deploy'" if $LOG.error? return end Awestruct::CLI::Deploy.new( config, deploy_config ).run end |
#invoke_force ⇒ Object
98 99 100 101 |
# File 'lib/awestruct/cli/invoker.rb', line 98 def invoke_force() FileUtils.rm_rf( File.join( config.dir, '.awestruct', 'dependency-cache' ) ) FileUtils.rm_rf( config.output_dir ) end |
#invoke_generate ⇒ Object
103 104 105 |
# File 'lib/awestruct/cli/invoker.rb', line 103 def invoke_generate() @success = Awestruct::CLI::Generate.new( config, .profile, .base_url, 'http://localhost:4242', .force ).run end |
#invoke_init ⇒ Object
91 92 93 |
# File 'lib/awestruct/cli/invoker.rb', line 91 def invoke_init() Awestruct::CLI::Init.new( Dir.pwd, .framework, .scaffold ).run end |
#invoke_script ⇒ Object
95 96 |
# File 'lib/awestruct/cli/invoker.rb', line 95 def invoke_script() end |
#invoke_server ⇒ Object
122 123 124 |
# File 'lib/awestruct/cli/invoker.rb', line 122 def invoke_server() run_in_thread( Awestruct::CLI::Server.new( './_site', .bind_addr, .port ) ) end |
#load_profile ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/awestruct/cli/invoker.rb', line 57 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 .profile profiles_data[.profile] || {} else # if no profile given, pick the first with deploy config .profile, profile_data = profiles_data.select { |k,v| v && v['deploy'] }.first profile_data end end end end unless @profile $LOG.error "Unable to locate profile: #{.profile}" if .profile && $LOG.error? .profile = 'NONE' @profile = {} end $LOG.info "Using profile: #{.profile}" if $LOG.info? end |