Class: Dplyr::Cli

Inherits:
Object
  • Object
show all
Includes:
Dply::Logger
Defined in:
lib/dplyr/cli.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Dply::Logger

#debug?, #logger, stderr, #stderr

Constructor Details

#initialize(stage, argv) ⇒ Cli

Returns a new instance of Cli.



11
12
13
14
# File 'lib/dplyr/cli.rb', line 11

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

Instance Attribute Details

#argvObject (readonly)

Returns the value of attribute argv.



10
11
12
# File 'lib/dplyr/cli.rb', line 10

def argv
  @argv
end

#stageObject (readonly)

Returns the value of attribute stage.



10
11
12
# File 'lib/dplyr/cli.rb', line 10

def stage
  @stage
end

Instance Method Details

#argv_strObject



61
62
63
# File 'lib/dplyr/cli.rb', line 61

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

#env_strObject



53
54
55
56
57
58
59
# File 'lib/dplyr/cli.rb', line 53

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

#hostsObject



45
46
47
# File 'lib/dplyr/cli.rb', line 45

def hosts
  stage_data[:hosts]
end

#parallel_jobsObject



49
50
51
# File 'lib/dplyr/cli.rb', line 49

def parallel_jobs
  stage_data[:parallel_runs]
end

#runObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/dplyr/cli.rb', line 16

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

#run_remote_taskObject



65
66
67
68
# File 'lib/dplyr/cli.rb', line 65

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

#stage_dataObject



41
42
43
# File 'lib/dplyr/cli.rb', line 41

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