Class: Blender::Cli::Init

Inherits:
Blender::Cli show all
Defined in:
lib/blender/cli/init.rb

Instance Method Summary collapse

Methods inherited from Blender::Cli

#initialize, #run

Constructor Details

This class inherits a constructor from Blender::Cli

Instance Method Details

#bootstrap(options) ⇒ Object



43
44
45
46
47
48
49
50
# File 'lib/blender/cli/init.rb', line 43

def bootstrap(options)
  extra=""
  extra << " TRACE=1" if options[:trace]
  extra << " HOSTNAME=#{options[:hostname]}" if options[:hostname]
  extra << " NODE=#{options[:node]}" if options[:node]

  run "cat #{File.expand_path("files/bootstrap.sh", Blender::ROOT)} | ssh #{options[:host]} USE_SYSTEM_GEMS=#{options[:system_gems]}#{extra} /bin/bash -eu" or raise "failed bootstrap.sh"
end

#executeObject



52
53
54
55
56
57
58
# File 'lib/blender/cli/init.rb', line 52

def execute
  options = parse_options(@args)
  bootstrap(options)

rescue => e
  abort(e.to_s)
end

#parse_options(args) ⇒ Object



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
# File 'lib/blender/cli/init.rb', line 4

def parse_options(args)
  options = {
    :system_gems => 'y'
  }
  opts = OptionParser.new do |opts|
    opts.banner = "Usage: blender init [OPTIONS] HOST"
    opts.separator ""
    opts.separator "Common options:"

    opts.on("-u", "--upstream-gems", "don't use the system gems, download and install upstream version instead") do
      options[:system_gems] = 'n'
    end

    opts.on("-N", "--node NODE", "force NODE as the current nodename") do |val|
      options[:node] = val
    end

    opts.on("-t", "--trace", "dump trace to the stdout") do |val|
      options[:trace] = true
    end

    opts.on("-H", "--hostname HOSTNAME", "set HOSTNAME") do |val|
      options[:hostname] = val
    end

    opts.on("-h", "--help", "Show this message") do
      raise(opts.to_s)
    end

  end
  opts.parse!(args)

  raise("please provide a hostname\n#{opts}") unless host = args.shift

  raise("unexpected: #{args*" "}\n#{opts}") unless args.empty?

  options.merge(:host => host)
end