$:.push File.expand_path(File.dirname(__FILE__)) require 'rubygems' require 'rainbow' require 'gli' require 'gli_version' require 'bozo/bozo' require 'bozo/runner' require 'bozo/executor' require 'bozo/bozo_configuration' require 'bozo/configuration_error' require 'bozo/execution_error' include GLI # Set the location of the bozo runtime configuration file config_file '.bozorc' version Bozo::VERSION desc 'Run as a build server, allows more destructive actions' switch 'build-server' default_config_file = 'bozorc.rb' desc "The build configuration file (defaults to #{default_config_file})" default_value default_config_file arg_name 'path' flag 'config-file' default_environment = 'development' desc "The build environment (defaults to #{default_environment})" default_value default_environment arg_name 'name' flag :environment pre do |global_options, command, options, arguments| # Dump a view of the provided options. puts '## GLOBAL OPTIONS ##'.color(:cyan).bright puts global_options puts '' unless command.nil? puts '## COMMAND ##'.color(:cyan).bright puts command.names puts '' end puts '## OPTIONS ##'.color(:cyan).bright puts options puts '' unless arguments.empty? puts '## ARGUMENTS ##'.color(:cyan).bright puts arguments puts '' end # Load the configuration file. config = Bozo::BozoConfiguration.new config.load global_options[:'config-file'] puts "Building #{config.version} using Bozo #{Bozo::VERSION}" puts '' # Initialize the executor. @executor = Bozo::Executor.new config, global_options true end # Helper method for defining a command that invokes a bozo task. # # The first provided name will be passed on to bozo. # # Takes an optional block for defining command-specific flags and switches. # # @param [Symbol] command_names # The names to give the command. def bozo_command(*command_names) command_name = command_names.first command command_names do |c| yield c if block_given? c.action do |global_options, options, arguments| @executor.execute command_name, options, ENV.to_hash end end end desc 'Remove bozo and all its artifacts' bozo_command :uninstall desc 'Remove all build artifacts' bozo_command :clean desc 'Retrieve all project dependencies' bozo_command :dependencies desc 'Compile the project' bozo_command :compile, :c desc 'Run the tests for the project' bozo_command :test, :t desc 'Create a package' bozo_command :package, :p desc 'Publish a package' bozo_command :publish on_error do |exception| puts exception.inspect.color(:red).bright if exception.kind_of? Bozo::ExecutionError or exception.kind_of? Bozo::ConfigurationError false else puts '' puts exception.backtrace.join("\n").color(:red) true end end