Sha256: 43647b9f14297fa1fc632cce20682bb80bf88e0da8e1b2f6f5c29ee9e7425cfc

Contents?: true

Size: 1.82 KB

Versions: 23

Compression:

Stored size: 1.82 KB

Contents

require 'dply/logger'
require 'dply/lock'
require 'fileutils'
require 'erb'

module Dply
  module Cli
    class Setup

      include ::Dply::Logger

      def initialize(argv)
        @argv = argv
        @options = {}
      end

      def run
        opts.parse!(@argv)
        return if not proceed?
        lock.acquire
        setup_default
        setup_app_rake
      end

      def proceed?
        print "Are you sure?(y/n) "
        v = STDIN.gets.strip
        v == "y"
      end

      def setup_default
        if not File.exist? "dply"
          FileUtils.mkdir_p "dply"
          logger.info "created dply/"
        else
          logger.info "skipping dply/"
        end

        rakefile = "dply/Rakefile"
        if not File.exist? rakefile
          FileUtils.touch rakefile
          logger.info "created #{rakefile}"
        else
          logger.info "skipping #{rakefile}"
        end
        
        pkgs_yml = "pkgs.yml"
        if not File.exist? pkgs_yml
          FileUtils.cp "#{templates_dir}/pkgs.erb", pkgs_yml
          logger.info "created #{pkgs_yml}"
        else
          logger.info "skipping #{pkgs_yml}"
        end
      end

      def setup_app_rake
        tasks_file = "dply/app.rake"
        if File.exist? tasks_file
          logger.info "skipping #{tasks_file}"
          return
        end
        FileUtils.cp "#{templates_dir}/deploy.erb", tasks_file
        logger.info "created #{tasks_file}"
      end

      def templates_dir
        @templates_dir ||= "#{__dir__}/../templates"
      end

      def lock
        @lock ||= ::Dply::Lock.new
      end

      def opts
        OptionParser.new do |opts|

          opts.banner = "Usage: drake setup [options] [namespace]"

          opts.on("-h", "--help", "Help") do
            puts opts
            exit
          end
        end
      end

    end
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
dply-0.3.15 lib/dply/cli/setup.rb
dply-0.3.14 lib/dply/cli/setup.rb
dply-0.3.13 lib/dply/cli/setup.rb
dply-0.3.12 lib/dply/cli/setup.rb
dply-0.3.11 lib/dply/cli/setup.rb
dply-0.3.10 lib/dply/cli/setup.rb
dply-0.3.9 lib/dply/cli/setup.rb
dply-0.3.8 lib/dply/cli/setup.rb
dply-0.3.7 lib/dply/cli/setup.rb
dply-0.3.6 lib/dply/cli/setup.rb
dply-0.3.5 lib/dply/cli/setup.rb
dply-0.3.4 lib/dply/cli/setup.rb
dply-0.3.3 lib/dply/cli/setup.rb
dply-0.3.2 lib/dply/cli/setup.rb
dply-0.3.1 lib/dply/cli/setup.rb
dply-0.3.0 lib/dply/cli/setup.rb
dply-0.2.19 lib/dply/cli/setup.rb
dply-0.2.18 lib/dply/cli/setup.rb
dply-0.2.17 lib/dply/cli/setup.rb
dply-0.2.16 lib/dply/cli/setup.rb