Sha256: 328b493109c8b9577fb5b96cda53b24aa249c8a98a445fa6fb34fb10309e2eec

Contents?: true

Size: 1.39 KB

Versions: 20

Compression:

Stored size: 1.39 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
        when "first"
          stage_data[:hosts] = [hosts.first] if hosts.size > 0
          argv.shift
          run_remote_task
        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

20 entries across 20 versions & 1 rubygems

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