Class: Travis::CLI::Lint
- Inherits:
-
ApiCommand
- Object
- Command
- ApiCommand
- Travis::CLI::Lint
- Defined in:
- lib/travis/cli/lint.rb
Constant Summary
Constants inherited from Command
Command::DAY, Command::HOUR, Command::MINUTE, Command::WEEK
Constants included from Tools::Assets
Instance Attribute Summary
Attributes inherited from ApiCommand
Attributes inherited from Command
#arguments, #config, #debug, #force_interactive, #formatter, #input, #output
Instance Method Summary collapse
Methods inherited from ApiCommand
#authenticate, #detected_endpoint?, #endpoint_config, #enterprise?, #initialize, #pro?, #setup, #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, #job, #lint, #listen, #logout, #regenerate_token, #remove_token, #repo, #repos, #restart, #user
Methods inherited from Command
abstract, abstract?, #check_completion, #check_ruby, #check_version, command_name, #command_name, #debug?, description, #error, #execute, #help, #info, #initialize, #last_check, #on_signal, #parse, #say, #setup, skip, subcommands, #terminal, #time, #usage, #usage_for, #warn, #write_to
Methods included from Tools::Assets
Methods included from Parser
Constructor Details
This class inherits a constructor from Travis::CLI::ApiCommand
Instance Method Details
#run(file = nil) ⇒ Object
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 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/travis/cli/lint.rb', line 13 def run(file = nil) file ||= '.travis.yml' if $stdin.tty? || $stdin.eof? if file && (file != '-') debug "reading #{file}" error "file does not exist: #{color(file, :bold)}" unless File.exist? file error "cannot read #{color(file, :bold)}" unless File.readable? file content = File.read(file) else debug 'reading stdin' file = 'STDIN' content = $stdin.read end begin YAML.load(content) rescue Psych::SyntaxError => e error "#{file} is not valid YAML: #{e.message}" end lint = session.lint(content) unless quiet? if lint.ok? say 'valid', color("Hooray, #{file} looks %s :)", :success) else say "Warnings for #{color(file, :info)}:" lint.warnings.each do |warning| say "#{color('[x]', %i[red bold])} " if warning.key.any? say [ color('in ', :info), color(warning.key.join('.'), i[info bold underline]), color(' section:', :info), ' ' ].join end say warning..gsub(/"(.*?)"/) { color(::Regexp.last_match(1), i[info important]) } end end end exit 1 if lint.warnings? && exit_code? end |