Sha256: e0607820493f5e061fb7772ec294cfcc95d4a0633c30eb6310d9757fa7f881bb

Contents?: true

Size: 1.46 KB

Versions: 7

Compression:

Stored size: 1.46 KB

Contents

require 'travis/tools/assets'
require 'travis/cli'
require 'fileutils'
require 'erb'

module Travis
  module Tools
    module Completion
      RCS = ['.zshrc', '.bashrc'].map { |f| File.expand_path(f, ENV['HOME']) }
      include FileUtils
      extend self

      def config_path
        ENV.fetch('TRAVIS_CONFIG_PATH') { File.expand_path('.travis', ENV['HOME']) }
      end

      def cmp_file
        File.expand_path('travis.sh', config_path)
      end

      def install_completion
        update_completion
        source = "source " << cmp_file

        RCS.each do |file|
          next unless File.exist? file and File.writable? file
          next if File.read(file).include? source
          File.open(file, "a") { |f| f.puts("", "# added by travis gem", "[ ! -s #{cmp_file} ] || #{source}") }
        end
      end

      def update_completion
        mkdir_p(config_path)
        cp(Assets['travis.sh'], cmp_file)
      end

      def completion_installed?
        source = "source " << config_path
        RCS.each do |file|
          next unless File.exist? file and File.writable? file
          return false unless File.read(file).include? source
        end
        true
      end

      def compile
        commands = Travis::CLI.commands.sort_by { |c| c.command_name }
        template = Assets.read('travis.sh.erb')
        source   = ERB.new(template).result(binding).gsub(/^ +\n/, '')
        File.write(Assets['travis.sh'].first, source)
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
travis-1.10.0.pre.rc3 lib/travis/tools/completion.rb
travis-1.10.0.pre.rc2 lib/travis/tools/completion.rb
travis-1.9.2.travis.1288.9 lib/travis/tools/completion.rb
travis-1.9.2.travis.1285.9 lib/travis/tools/completion.rb
travis-1.9.2.travis.1279.9 lib/travis/tools/completion.rb
travis-1.10.0.pre.rc1 lib/travis/tools/completion.rb
travis-1.9.2.travis.1254.9 lib/travis/tools/completion.rb