Sha256: 3ccf2da3b26291df9268c2f72d692eb28a8f94c80d6e3481acd577b92d1af713

Contents?: true

Size: 1.71 KB

Versions: 2

Compression:

Stored size: 1.71 KB

Contents

module OpsPreflight
  class Client < Thor
    include Thor::Actions
    include ExitCode

    namespace :default

    source_root OpsPreflight.root_path

    class_option :verbose, :aliases => '-v', :type => :boolean
    class_option :simulate, :aliases => '-S', :type => :boolean
    class_option :trace, :aliases => '-t', :type => :boolean

    desc "init", "Initialize application to work with preflight"
    def init
      copy_file 'data/preflight.yml', 'config/preflight.yml'
      say 'Please edit config/preflight.yml to finish setting up preflight.'
    end

    desc "setup <rails_env>", "Set up the server's preflight environment"
    def setup(rails_env)
      run "bundle exec mina setup RAILS_ENV=#{rails_env} #{Config.new.client_args(rails_env)} #{mina_args}", :verbose => false
    end

    desc "deploy <rails_env>", "Deploys to the configured app"
    option :ember, type: :boolean, default: false
    option :ember_only, type: :boolean, default: false
    def deploy(rails_env)
      run "bundle exec mina deploy RAILS_ENV=#{rails_env} DEPLOY_EMBER=#{options[:ember]} EMBER_ONLY=#{options[:ember_only]} #{Config.new.client_args(rails_env)} #{mina_args}", :verbose => false
    end

    # Fixes thor's banners when used with :default namespace
    def self.banner(command, namespace = nil, subcommand = false)
      "#{basename} #{command.formatted_usage(self, false, subcommand)}"
    end

    no_tasks do
      def mina_args(*args)
        args = "-f #{OpsPreflight.root_path('data', 'deploy.rb')}"

        # mina's --verbose doesn't work
        args << ' -v' if options[:verbose]

        [:simulate, :trace].each do |opt|
          args << " --#{opt.to_s}" if options[opt]
        end

        args
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ops_preflight-1.3.1 lib/ops_preflight/client.rb
ops_preflight-1.3.0 lib/ops_preflight/client.rb