Class: GcloudHosts::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/gcloud_hosts/runner.rb

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Runner

Returns a new instance of Runner.



6
7
8
# File 'lib/gcloud_hosts/runner.rb', line 6

def initialize(args)
  @options = Options.new(args).options
end

Instance Method Details

#run!Object



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
# File 'lib/gcloud_hosts/runner.rb', line 10

def run!
  project = @options[:project].to_s.strip
  if @options[:clear]
    if project != ""
      raise ArgumentError.new("Cannot specify 'clear' and 'project' at the same time.")
    end
  end
  if project == ""
    project = env["core"]["project"].to_s.strip
  end

  backup = @options[:backup] ||
    @options[:file] + '.bak'

  if @options[:clear]
    Updater.clear(@options[:file], backup, @options[:dry_run])
  else
    if project == ""
      raise AuthError.new("No gcloud project specified.")
    end
    if @options[:domain]
      domain = @options[:domain].to_s.strip
    else
      domain = "c.#{project}.internal"
    end

    if @options[:delete]
      new_hosts_list = []
    else
      new_hosts_list = Hosts.hosts(@options[:gcloud], project, @options[:network], domain, @options[:public], @options[:exclude_public])
    end
    Updater.update(new_hosts_list.join("\n"), project, @options[:file], backup, @options[:dry_run], @options[:delete])
  end
end