lib/awestruct/cli/invoker.rb in awestruct-0.5.4.rc3 vs lib/awestruct/cli/invoker.rb in awestruct-0.5.4

- old
+ new

@@ -1,9 +1,10 @@ require 'pathname' require 'logger' require 'awestruct/logger' require 'awestruct/cli/options' +require 'awestruct/util/exception_helper' module Awestruct module CLI class Invoker @@ -35,62 +36,76 @@ require 'awestruct/cli/auto' require 'awestruct/cli/server' end def invoke! - load_profile() unless ( options.init ) + begin + load_profile() unless ( options.init ) - setup_config() + 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 ) + 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 + wait_for_completion() + @success = false if ExceptionHelper.build_failed? + rescue + @success = false + false + end end 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 + 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 - - unless @profile - $LOG.error "Unable to locate profile: #{options.profile}" if options.profile && $LOG.error? - options.profile = 'NONE' - @profile = {} - end - $LOG.info "Using profile: #{options.profile}" if $LOG.info? + + site_yaml = YAML.load( File.read( site_yaml_file ) ) + + if ( !site_yaml ) + abort( "Failed to parse #{site_yaml_file}" ) + end + + profiles = site_yaml['profiles'] || {} + + profile_name = options.profile + + # use the one specified + profile = profiles[profile_name] + if ( !profile ) + profile_name, profile = if ( options.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 def setup_config() @config = Awestruct::Config.new( @options ) @config.track_dependencies = true if ( @options.auto ) @config.verbose = true if ( @options.verbose ) + @config.quiet = true if ( @options.quiet ) end def invoke_init() - Awestruct::CLI::Init.new( Dir.pwd, @options.framework, @options.scaffold ).run + Awestruct::CLI::Init.new( @options.source_dir, @options.framework, @options.scaffold ).run end def invoke_script() end @@ -116,10 +131,11 @@ Awestruct::CLI::Deploy.new( config, deploy_config ).run end def invoke_auto() - Awestruct::CLI::Auto.new( config ).run + base_url = profile['base_url'] || options.base_url + Awestruct::CLI::Auto.new( config, base_url ).run end def invoke_server() run_in_thread( Awestruct::CLI::Server.new( options.output_dir, options.bind_addr, options.port ) ) end