Class: TerraformEnterprise::CommandLine::Commands::RunsCommand

Inherits:
TerraformEnterprise::CommandLine::Command show all
Defined in:
lib/terraform_enterprise/command_line/commands/runs.rb

Constant Summary collapse

ATTR_STR =
STRINGS[:runs][:attributes]
CMD_STR =
STRINGS[:runs][:commands]

Constants included from TerraformEnterprise::CommandLine

STRINGS, VERSION

Instance Method Summary collapse

Methods included from Util::Tar

#gzip, #tar, #tarball

Instance Method Details

#apply(id) ⇒ Object



32
33
34
35
36
# File 'lib/terraform_enterprise/command_line/commands/runs.rb', line 32

def apply(id)
  params = { id: id, action: :apply }
  params[:comment] = options[:comment] if options[:comment]
  render client.runs.action(params)
end

#createObject



21
22
23
# File 'lib/terraform_enterprise/command_line/commands/runs.rb', line 21

def create
  render client.runs.create(options), except: [:permissions]
end

#discard(id) ⇒ Object



40
41
42
43
44
# File 'lib/terraform_enterprise/command_line/commands/runs.rb', line 40

def discard(id)
  params = { id: id, action: :discard }
  params[:comment] = options[:comment] if options[:comment]
  render client.runs.action(params)
end

#get(id) ⇒ Object



26
27
28
# File 'lib/terraform_enterprise/command_line/commands/runs.rb', line 26

def get(id)
  render client.runs.get(id: id), except: [:permissions]
end

#listObject



13
14
15
# File 'lib/terraform_enterprise/command_line/commands/runs.rb', line 13

def list
  render client.runs.list(id: options[:workspace_id]), except: [:permissions]
end

#logs(id) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/terraform_enterprise/command_line/commands/runs.rb', line 49

def logs(id)
  following       = options[:follow]
  finished        = false
  exit_requested  = false
  finished_states = %w[errored canceled finished]

  # Listens for "control-c" to exit
  Kernel.trap('INT') { exit_requested = true }

  loop do
    event    = get_event_resource(id, options[:event])
    url      = event.attributes['log-read-url']
    finished = finished_states.include?(event.attributes['status'].to_s)
    logs     = RestClient.get(url).body
    
    # errase screen and go to (0,0)
    print "\033[2J" if following
    print logs

    break if !following || exit_requested || finished
    
    sleep 2
  end 
end