Class: Grifork::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/grifork/cli.rb

Instance Method Summary collapse

Instance Method Details

#load_taskfilesObject (private)



49
50
51
52
53
54
55
56
57
58
# File 'lib/grifork/cli.rb', line 49

def load_taskfiles
  puts "Load settings from #{taskfile}"
  dsl = Grifork::DSL.load_file(taskfile, on_remote: @on_remote)
  if @override_file
    dsl.load_and_merge_config_by!(@override_file)
  end
  config = dsl.to_config
  config.griforkfile = taskfile
  config
end

#run(argv) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/grifork/cli.rb', line 2

def run(argv)
  OptionParser.new do |opt|
    opt.on('-f', '--file Griforkfile') { |f| @taskfile      = f }
    opt.on('-o', '--override-by FILE') { |f| @override_file = f }
    opt.on('-r', '--on-remote')        { @on_remote = true }
    opt.on('-n', '--dry-run')          { @dry_run   = true }
    opt.on('-v', '--version')          { @version   = true }
    opt.parse!(argv)
  end
  if @version
    puts Grifork::VERSION
    exit
  end

  config = load_taskfiles
  if @dry_run
    config.dry_run = true
  end
  config.freeze
  Grifork.configure!(config)
  logger = Grifork.logger

  graph = Grifork::Graph.new(config.hosts)

  logger.info("START | mode: #{config.mode}")
  if @on_remote
    puts "Start on remote. Hosts: #{config.hosts}"
  end

  case config.mode
  when :standalone
    graph.launch_tasks
  when :grifork
    graph.grifork
  else
    # Never comes here
    raise "Unexpected mode! #{config.mode}"
  end

  logger.info("END | mode: #{config.mode}")
  if @on_remote
    puts "End on remote."
  end
end

#taskfileObject (private)



60
61
62
# File 'lib/grifork/cli.rb', line 60

def taskfile
  @taskfile || ENV['GRIFORKFILE'] || Grifork::DEFAULT_TASKFILE
end