Class: Travis::CLI::Logs

Inherits:
RepoCommand show all
Includes:
Tools::SafeString
Defined in:
lib/travis/cli/logs.rb

Constant Summary

Constants inherited from RepoCommand

RepoCommand::GIT_REGEX, RepoCommand::TRAVIS

Constants inherited from Command

Command::DAY, Command::HOUR, Command::MINUTE, Command::WEEK

Constants included from Tools::Assets

Tools::Assets::BASE

Instance Attribute Summary collapse

Attributes inherited from RepoCommand

#slug

Attributes inherited from ApiCommand

#enterprise_name, #session

Attributes inherited from Command

#arguments, #config, #debug, #force_interactive, #formatter, #input, #output

Instance Method Summary collapse

Methods included from Tools::SafeString

#clean, #colorized, #encoded

Methods inherited from RepoCommand

#repository

Methods inherited from ApiCommand

#authenticate, #detected_endpoint?, #endpoint_config, #enterprise?, #initialize, #org?, #pro?, #sync

Methods included from Travis::Client::Methods

#access_token, #access_token=, #account, #accounts, #api_endpoint, #api_endpoint=, #artifact, #broadcasts, #build, #cancel, #explicit_api_endpoint?, #github_auth, #hooks, #lint, #listen, #repo, #repos, #restart, #user

Methods inherited from Command

abstract, abstract?, #check_completion, #check_ruby, #check_version, command_name, #command_name, #debug?, description, #execute, #help, #info, #initialize, #last_check, #on_signal, #parse, #say, skip, subcommands, #terminal, #time, #usage, #usage_for, #write_to

Methods included from Parser

#new, #on, #on_initialize

Methods included from Tools::Assets

#asset, #asset_path

Constructor Details

This class inherits a constructor from Travis::CLI::ApiCommand

Instance Attribute Details

#deleteObject

Returns the value of attribute delete


8
9
10
# File 'lib/travis/cli/logs.rb', line 8

def delete
  @delete
end

#reasonObject

Returns the value of attribute reason


8
9
10
# File 'lib/travis/cli/logs.rb', line 8

def reason
  @reason
end

Instance Method Details

#delete_log(job) ⇒ Object


26
27
28
29
30
31
32
33
34
# File 'lib/travis/cli/logs.rb', line 26

def delete_log(job)
  unless force?
    error "not deleting logs without --force" unless interactive?
    error "aborted" unless danger_zone? "Do you really want to delete the build log for #{color(job.inspect_info, :underline)}?"
  end

  warn "deleting log for #{color(job.inspect_info, [:bold, :info])}"
  job.delete_log(reason || {})
end

#display_log(job) ⇒ Object


36
37
38
39
40
41
42
# File 'lib/travis/cli/logs.rb', line 36

def display_log(job)
  info "displaying logs for #{color(job.inspect_info, [:bold, :info])}"
  return print_log(job.log.body) unless stream?
  job.log.body { |part| print_log(part) }
ensure
  print "\e[0m" if interactive?
end

44
45
46
# File 'lib/travis/cli/logs.rb', line 44

def print_log(part)
  print interactive? ? encoded(part) : clean(part)
end

#run(number = last_build.number) ⇒ Object


20
21
22
23
24
# File 'lib/travis/cli/logs.rb', line 20

def run(number = last_build.number)
  self.stream = true if stream.nil?
  job ||= job(number) || error("no such job ##{number}")
  delete ? delete_log(job) : display_log(job)
end

#setupObject


14
15
16
17
# File 'lib/travis/cli/logs.rb', line 14

def setup
  super
  check_websocket
end