Class: Travis::CLI::Settings

Inherits:
RepoCommand show all
Defined in:
lib/travis/cli/settings.rb

Constant Summary collapse

DESCRIPTIONS =
{
  builds_only_with_travis_yml: 'Only run builds with a .travis.yml',
  build_pushes: 'Build pushes',
  build_pull_requests: 'Build pull requests',
  maximum_number_of_builds: 'Maximum number of concurrent builds',
  auto_cancel_pushes: 'Cancel older push builds that are not yet running',
  auto_cancel_pull_requests: 'Cancel older pull request builds that are not yet running'
}.freeze

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 inherited from RepoCommand

#repository, #setup

Methods inherited from ApiCommand

#authenticate, #detected_endpoint?, #endpoint_config, #enterprise?, #initialize, #org?, #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

asset, asset_path

Methods included from Parser

#new, #on, #on_initialize

Constructor Details

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

Instance Attribute Details

#settingObject

Returns the value of attribute setting.



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

def setting
  @setting
end

Instance Method Details

#all_settings?Boolean

Returns:

  • (Boolean)


70
71
72
73
74
# File 'lib/travis/cli/settings.rb', line 70

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

#boolean?(key) ⇒ Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/travis/cli/settings.rb', line 58

def boolean?(key)
  key.to_sym != :maximum_number_of_builds
end

#describe(key, description = key) ⇒ Object



76
77
78
79
80
81
82
# File 'lib/travis/cli/settings.rb', line 76

def describe(key, description = key)
  return description if keys?

  desc = DESCRIPTIONS[key.to_sym]
  desc &&= yield(desc) if block_given?
  desc || description
end

#format_value(value) ⇒ Object



62
63
64
65
66
67
68
# File 'lib/travis/cli/settings.rb', line 62

def format_value(value)
  case value
  when false, nil then color('[-]', %i[bold red])
  when true       then color('[+]', %i[bold green])
  else color(value.to_s.rjust(3), %i[bold blue])
  end
end

#run(*keys) ⇒ Object



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
56
# File 'lib/travis/cli/settings.rb', line 26

def run(*keys)
  exit 1 if interactive? && keys.empty? && !setting.nil? && !all_settings? && !configure?
  authenticate
  say repository.slug, 'Settings for %s:'
  repository.settings.to_h.each do |key, value|
    next unless keys.empty? || keys.include?(key)

    if configure?
      repository.settings[key] = if boolean? key
                                   agree("#{describe(key, "enable #{key}")}? ") do |q|
                                     default   = setting.nil? ? value : setting
                                     q.default = default ? 'yes' : 'no'
                                   end
                                 else
                                   ask("#{describe(key, "Value for #{key}")}: ", Integer) do |q|
                                     default   = setting.to_i if setting && setting.respond_to?(:to_i)
                                     default ||= value
                                     default ||= 0
                                     q.default = default
                                   end
                                 end
    else
      value  = repository.settings[key] = setting unless setting.nil?
      descr  = color(describe(key, color(key, :info)) do |s|
                       "#{key.ljust(30)} #{color(s, %i[reset bold])}"
                     end, :info)
      say format_value(value) << ' ' << descr
    end
  end
  repository.settings.save if configure? || !setting.nil?
end