Sha256: 74ba02bfbcad10380f5028805a53e2e0da7e42d1e205d4d54a0e983095c900d1

Contents?: true

Size: 1.95 KB

Versions: 79

Compression:

Stored size: 1.95 KB

Contents

require 'travis/cli'

module Travis
  module CLI
    class Settings < RepoCommand
      attr_accessor :setting

      description "access repository settings"
      on('--keys', 'always use setting key instead of description')
      on('-t', '--enable',  'enable the setting(s)')  { |c| c.setting = true  }
      on('-f', '--disable', 'disable the setting(s)') { |c| c.setting = false }
      on('-c', '--configure', 'change settings interactively')

      DESCRIPTIONS = {
        :builds_only_with_travis_yml => "Only run builds with a .travis.yml",
        :build_pushes                => "Build pushes",
        :build_pull_requests         => "Build pull requests"
      }

      def run(*keys)
        exit 1 if interactive? and keys.empty? and !setting.nil? and !all_settings? and !configure?
        authenticate
        say repository.slug, "Settings for %s:"
        repository.settings.to_h.each do |key, value|
          next unless keys.empty? or keys.include? key
          if configure?
            repository.settings[key] = agree("#{describe(key, "enable #{key}")}? ") do |q|
              default   = setting.nil? ? value : setting
              q.default = default ? "yes" : "no"
            end
          else
            value = repository.settings[key] = setting unless setting.nil?
            descr = color(describe(key, color(key, :info)) { |s| key.ljust(30) + " " + color(s, [:reset, :bold]) }, :info)
            say color("[#{value ? "+" : "-"}] ", [:bold, value ? :green : :red]) << descr
          end
        end
        repository.settings.save if configure? or !setting.nil?
      end

      def all_settings?
        agree("Really #{setting ? "enable" : "disable"} all settings? ") do |q|
          q.default = "no"
        end
      end

      def describe(key, description = key)
        return description if keys?
        desc = DESCRIPTIONS[key.to_sym]
        desc &&= yield(desc) if block_given?
        desc || description
      end
    end
  end
end

Version data entries

79 entries across 79 versions & 1 rubygems

Version Path
travis-1.6.15.travis.565.6 lib/travis/cli/settings.rb
travis-1.6.15.travis.564.6 lib/travis/cli/settings.rb
travis-1.6.15.travis.563.6 lib/travis/cli/settings.rb
travis-1.6.15.travis.562.6 lib/travis/cli/settings.rb
travis-1.6.15.travis.561.6 lib/travis/cli/settings.rb
travis-1.6.15.travis.560.6 lib/travis/cli/settings.rb
travis-1.6.15.travis.559.6 lib/travis/cli/settings.rb
travis-1.6.15.travis.558.6 lib/travis/cli/settings.rb
travis-1.6.15.travis.557.6 lib/travis/cli/settings.rb
travis-1.6.15.travis.556.6 lib/travis/cli/settings.rb
travis-1.6.15.travis.555.6 lib/travis/cli/settings.rb
travis-1.6.15.travis.554.6 lib/travis/cli/settings.rb
travis-1.6.15.travis.552.6 lib/travis/cli/settings.rb
travis-1.6.15.travis.551.6 lib/travis/cli/settings.rb
travis-1.6.15.travis.550.6 lib/travis/cli/settings.rb
travis-1.6.15.travis.547.6 lib/travis/cli/settings.rb
travis-1.6.15.travis.544.6 lib/travis/cli/settings.rb
travis-1.6.14.travis.543.6 lib/travis/cli/settings.rb
travis-1.6.14 lib/travis/cli/settings.rb
travis-1.6.14.travis.539.6 lib/travis/cli/settings.rb