Sha256: 65f28716b1bf9ec3420b508e69012a7058d36f04b54852a662d06ecbaf341f7e

Contents?: true

Size: 1.27 KB

Versions: 10

Compression:

Stored size: 1.27 KB

Contents

require 'dplyr/stages_config'
require 'dplyr/task_runner'
require 'dply/logger'

module Dplyr
  class Cli

    include ::Dply::Logger

    attr_reader :stage, :argv
    def initialize(stage, argv)
      @stage = stage
      @argv = argv
    end

    def run
      global_switches = []
      global_switches << "--debug" if  logger.debug?
      case stage
      when 'dev'
        global_switches << "--no-config"
        system "drake #{global_switches.join(" ")} #{argv_str}"
      when 'local'
        system "drake #{global_switches.join(" ")} #{argv_str}"
      else
        command = argv[0]
        case command
        when "list"
          require 'pp'
          pp hosts
        else
          run_remote_task
        end
      end
    end

    def stage_data
      @stage_data ||= StagesConfig.new.fetch(@stage).data
    end

    def hosts
      stage_data[:hosts]
    end

    def parallel_jobs
      stage_data[:parallel_runs]
    end

    def env_str
      str = ""
      stage_data[:env].each do |k,v|
        str << %(DPLY_#{k.upcase}="#{v}" )
      end
      str
    end

    def argv_str
      @argv_str ||= argv.join(' ')
    end

    def run_remote_task
      task_runner  = TaskRunner.new(hosts, argv_str, parallel_jobs: parallel_jobs)
      task_runner.run
    end

  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
dply-0.2.14 lib/dplyr/cli.rb
dply-0.2.13 lib/dplyr/cli.rb
dply-0.2.11 lib/dplyr/cli.rb
dply-0.2.10 lib/dplyr/cli.rb
dply-0.2.9 lib/dplyr/cli.rb
dply-0.2.8 lib/dplyr/cli.rb
dply-0.2.7 lib/dplyr/cli.rb
dply-0.2.6 lib/dplyr/cli.rb
dply-0.2.5 lib/dplyr/cli.rb
dply-0.2.4 lib/dplyr/cli.rb