Sha256: 92d8c7fb4ab8e75244d754b8625824ed8eac4dca4e5a8c42fe62caf050abdc87

Contents?: true

Size: 1.82 KB

Versions: 2

Compression:

Stored size: 1.82 KB

Contents

#!/usr/bin/env ruby 
Signal.trap("INT") { exit 1 }

require 'optparse'
require 'dply/error'
require 'dply/version'
require 'dply/logger'
require 'dplyr/cli'
require 'pathname'

logger = ::Dply::Logger.logger
options = {}

opts_parser = OptionParser.new do |opts| 
    
    banner = [] 
    banner << "Usage: dplyr [global options] stage command [options] args"
    banner << "Commands:"
    banner << "    deploy"
    banner << "    switch"
    banner << "    rollback"
    
    banner << "Options: "
    opts.banner = banner.join("\n")

    opts.on("-d", "--deploy-dir [DEPLOY DIR]" , "Set deploy dir") do |d| 
      path = Pathname.new(d)
      raise ::Dply::Error, "deploy_dir path must be absolute" if path.relative?
      options[:deploy_dir] = path
    end 

    opts.on("-v", "--version", "Show version") do |v|
      puts ::Dply::VERSION
      exit
    end

    opts.on("--debug", "Show debug messages") do
      options[:debug] = true
      logger.level = ::Logger::DEBUG
    end

    opts.on("--trace", "Show debug messages and exception stack trace") do
      options[:debug] = true
      options[:trace] = true
      logger.level = ::Logger::DEBUG
    end

    opts.on("-m", "--enable-markers", "Enable marker logging") do
      logger.enable_markers = true
    end

    opts.on_tail("-h", "--help", "Show this message") do 
      puts opts
      exit
    end
end
begin
  opts_parser.order!(ARGV)
  deploy_dir = options[:deploy_dir] || Dir.pwd
  Dir.chdir deploy_dir

  stage = ARGV.shift

  dplyr = ::Dplyr::Cli.new(stage, ARGV)
  dplyr.run

rescue OptionParser::InvalidOption, OptionParser::MissingArgument, ::Dply::Error => e
  cause = e.cause
  if options[:trace]
    puts cause
    cause ? (raise cause) : (raise e)
  else
    logger.debug "#{cause.message}" if cause
    logger.error "#{e.message}"
    abort
  end
ensure
  logger.marker "end"
end


Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
dply-0.1.18 bin/dplyr
dply-0.1.17 bin/dplyr