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.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/awestruct/cli/invoker.rb', line 17 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 File.join(@options.source_dir, '.awestruct') logging_path.mkpath unless logging_path.exist? Logging.init :trace, :debug, :verbose, :info, :warn, :error, :fatal $LOG = Logging.logger.new 'awestruct' $LOG.add_appenders( Logging.appenders.stdout({level: (@options.verbose ? :verbose : :info), layout: Logging.layouts.pattern(pattern: "%m\n", format_as: :string), color_scheme: :default}), Logging.appenders.file('error', {filename: File.join(logging_path, 'error.log'), layout: Logging.layouts.parseable.json(format_as: :string), truncate: true, level: :error}) ) if @options.debug $LOG.add_appenders( Logging.appenders.file('debug', {filename: File.join(logging_path, 'debug.log'), layout: Logging.layouts.parseable.json(format_as: :string), truncate: true, level: :debug}) ) end if @options.perf_log $LOG.add_appenders( Logging.appenders.file('perf', {filename: File.join(logging_path, 'perf.log'), truncate: true, level: :trace, layout: Logging.layouts.parseable.json(format_as: :string), filters: Logging::Filters::Level.new(:trace)}) ) end # these requires are deferred until after $LOG is set require 'awestruct/cli/init' require 'awestruct/cli/generate' require 'awestruct/cli/auto' require 'awestruct/cli/server' end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
13 14 15 |
# File 'lib/awestruct/cli/invoker.rb', line 13 def config @config end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
11 12 13 |
# File 'lib/awestruct/cli/invoker.rb', line 11 def @options end |
#profile ⇒ Object (readonly)
Returns the value of attribute profile.
14 15 16 |
# File 'lib/awestruct/cli/invoker.rb', line 14 def profile @profile end |
#success ⇒ Object (readonly)
Returns the value of attribute success.
15 16 17 |
# File 'lib/awestruct/cli/invoker.rb', line 15 def success @success end |
Instance Method Details
#invoke! ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/awestruct/cli/invoker.rb', line 65 def invoke! begin 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() if ExceptionHelper.build_failed? || @success == false @success = false false else true end rescue => e $LOG.fatal "Caught exception; exiting" $LOG.fatal e @success = false false end end |
#invoke_auto ⇒ Object
170 171 172 173 |
# File 'lib/awestruct/cli/invoker.rb', line 170 def invoke_auto() base_url = profile['base_url'] || .base_url Awestruct::CLI::Auto.new( config, base_url ).run end |
#invoke_deploy ⇒ Object
157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'lib/awestruct/cli/invoker.rb', line 157 def invoke_deploy() require 'awestruct/cli/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
147 148 149 150 |
# File 'lib/awestruct/cli/invoker.rb', line 147 def invoke_force() FileUtils.rm_rf( File.join( config.dir, '.awestruct', 'dependency-cache' ) ) FileUtils.rm_rf( config.output_dir ) end |
#invoke_generate ⇒ Object
152 153 154 155 |
# File 'lib/awestruct/cli/invoker.rb', line 152 def invoke_generate() base_url = profile['base_url'] || .base_url @success = Awestruct::CLI::Generate.new( config, .profile, base_url, Options::DEFAULT_BASE_URL, .force, !.generate_on_access ).run end |
#invoke_init ⇒ Object
140 141 142 |
# File 'lib/awestruct/cli/invoker.rb', line 140 def invoke_init() Awestruct::CLI::Init.new( @options.source_dir, @options.framework, @options.scaffold ).run end |
#invoke_script ⇒ Object
144 145 |
# File 'lib/awestruct/cli/invoker.rb', line 144 def invoke_script() end |
#invoke_server ⇒ Object
175 176 177 |
# File 'lib/awestruct/cli/invoker.rb', line 175 def invoke_server() run_in_thread( Awestruct::CLI::Server.new( .output_dir, .bind_addr, .port, .generate_on_access ) ) end |
#load_profile ⇒ Object
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/awestruct/cli/invoker.rb', line 95 def load_profile() site_yaml_file = File.join( @options.source_dir, '_config', 'site.yml' ) if ( !File.exist?( site_yaml_file ) ) abort( "No config file at #{site_yaml_file}" ) end site_yaml = YAML.load( ERB.new(File.read( site_yaml_file ), trim_mode: '<>').result ) if ( !site_yaml ) abort( "Failed to parse #{site_yaml_file}" ) end profiles = site_yaml['profiles'] || {} profile_name = .profile # use the one specified profile = profiles[profile_name] if ( !profile ) profile_name, profile = if ( .deploy ) # or the first one having a deploy section profiles.select { |k,v| v && v['deploy'] } else # or the first one having no deploy section profiles.select { |k,v| v && !v['deploy'] } end.first end if profile $LOG.info "Using profile: #{profile_name}" if $LOG.info? end @profile = profile || {} end |
#setup_config ⇒ Object
131 132 133 134 135 136 137 138 |
# File 'lib/awestruct/cli/invoker.rb', line 131 def setup_config() @config = Awestruct::Config.new( @options ) @config.track_dependencies = true if ( @options.auto ) @config.verbose = true if ( @options.verbose ) @config.debug = @options.debug @config.quiet = true if @options.quiet @config.perf = true if @options.perf_log end |