Sha256: 0ba10cb3bfd18eb94c6c58e189576a0109bbcfb3943efdc765eadaf08048ad0a

Contents?: true

Size: 1.67 KB

Versions: 46

Compression:

Stored size: 1.67 KB

Contents

require 'travis/cli'
require 'yaml'

module Travis
  module CLI
    class Lint < ApiCommand
      description 'display warnings for a .travis.yml'
      on '-q', '--[no-]quiet',     'does not print anything'
      on '-x', '--[no-]exit-code', 'sets the exit code to 1 if there are warning'

      def run(file = nil)
        file ||= '.travis.yml' if $stdin.tty? or $stdin.eof?

        if file and 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]', [:red, :bold]) + " "
              if warning.key.any?
                say [
                  color('in ', :info),
                  color(warning.key.join('.'), [:info, :bold, :underline]),
                  color(' section:', :info), ' '
                ].join
              end
              say warning.message.gsub(/"(.*?)"/) { color($1, [:info, :important]) }
            end
          end
        end

        exit 1 if lint.warnings? and exit_code?
      end
    end
  end
end

Version data entries

46 entries across 46 versions & 1 rubygems

Version Path
travis-1.11.1 lib/travis/cli/lint.rb
travis-1.11.0 lib/travis/cli/lint.rb
travis-1.10.1.travis.1341.9 lib/travis/cli/lint.rb
travis-1.10.1.travis.1321.9 lib/travis/cli/lint.rb
travis-1.10.1.travis.1312.9 lib/travis/cli/lint.rb
travis-1.10.1.travis.1311.9 lib/travis/cli/lint.rb
travis-1.10.1.travis.1305.9 lib/travis/cli/lint.rb
travis-1.10.0 lib/travis/cli/lint.rb
travis-1.9.2.travis.1304.9 lib/travis/cli/lint.rb
travis-1.9.2.travis.1303.9 lib/travis/cli/lint.rb
travis-1.10.0.pre.rc4 lib/travis/cli/lint.rb
travis-1.10.0.pre.rc3 lib/travis/cli/lint.rb
travis-1.10.0.pre.rc2 lib/travis/cli/lint.rb
travis-1.9.2.travis.1288.9 lib/travis/cli/lint.rb
travis-1.9.2.travis.1285.9 lib/travis/cli/lint.rb
travis-1.9.2.travis.1279.9 lib/travis/cli/lint.rb
travis-1.10.0.pre.rc1 lib/travis/cli/lint.rb
travis-1.9.2.travis.1254.9 lib/travis/cli/lint.rb
travis-1.9.2.travis.1236.9 lib/travis/cli/lint.rb
travis-1.9.2.travis.1224.9 lib/travis/cli/lint.rb