Sha256: e7e825897bc8ac9abb4e9a7694d8be0b0a955114a1ae2f5b9c6f28ae7e932356

Contents?: true

Size: 1.15 KB

Versions: 13

Compression:

Stored size: 1.15 KB

Contents

require 'dplyr/stages_config'
require 'dplyr/remote_task'
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
        run_remote_task
      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
      remote_task = RemoteTask.new(hosts, argv_str, parallel_jobs: parallel_jobs, env: env_str)
      remote_task.run
    end

  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
dply-0.1.13 lib/dplyr/cli.rb
dply-0.1.12 lib/dplyr/cli.rb
dply-0.1.11 lib/dplyr/cli.rb
dply-0.1.10 lib/dplyr/cli.rb
dply-0.1.9 lib/dplyr/cli.rb
dply-0.1.8 lib/dplyr/cli.rb
dply-0.1.7 lib/dplyr/cli.rb
dply-0.1.6 lib/dplyr/cli.rb
dply-0.1.5 lib/dplyr/cli.rb
dply-0.1.4 lib/dplyr/cli.rb
dply-0.1.2 lib/dplyr/cli.rb
dply-0.1.1 lib/dplyr/cli.rb
dply-0.1.0 lib/dplyr/cli.rb