Class: Travis::CLI::Encrypt

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

Constant Summary

Constants inherited from RepoCommand

RepoCommand::GIT_REGEX

Instance Attribute Summary collapse

Attributes inherited from RepoCommand

#slug

Attributes inherited from ApiCommand

#session

Attributes inherited from Command

#arguments, #config, #force_interactive, #formatter, #input, #output

Instance Method Summary collapse

Methods inherited from RepoCommand

#repository, #setup

Methods inherited from ApiCommand

#authenticate, #detected_endpoint?, #endpoint_config, #initialize, #org?, #pro?, #setup, #sync

Methods included from Travis::Client::Methods

#access_token, #access_token=, #accounts, #api_endpoint, #api_endpoint=, #artifact, #broadcasts, #build, #cancel, #explicit_api_endpoint?, #github_auth, #job, #listen, #repo, #repos, #restart, #user, #worker, #workers

Methods inherited from Command

abstract, abstract?, #check_ruby, #check_version, command_name, #command_name, #debug, description, #execute, #help, #info, #initialize, #last_check, #on_signal, #parse, #say, #setup, skip, #terminal, #usage, #write_to

Methods included from Parser

#new, #on, #on_initialize

Constructor Details

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

Instance Attribute Details

#config_keyObject

Returns the value of attribute config_key.



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

def config_key
  @config_key
end

Instance Method Details

#run(*args) ⇒ Object



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
# File 'lib/travis/cli/encrypt.rb', line 18

def run(*args)
  error "cannot combine --override and --append"   if append?   and override?
  error "--append without --add makes no sense"    if append?   and not add?
  error "--override without --add makes no sense"  if override? and not add?
  self.override |= !config_key.start_with?('env.') if add?      and not append?

  if args.first =~ %r{\w+/\w+} && !args.first.include?("=")
    warn "WARNING: The name of the repository is now passed to the command with the -r option:"
    warn "    #{command("encrypt [...] -r #{args.first}")}"
    warn "  If you tried to pass the name of the repository as the first argument, you"
    warn "  probably won't get the results you wanted.\n"
  end

  data = args.join(" ")

  if data.empty?
    say color("Reading from stdin, press Ctrl+D when done", :info) if $stdin.tty?
    data = $stdin.read
  end

  data = split? ? data.split("\n") : [data]
  encrypted = data.map { |data| repository.encrypt(data) }

  if config_key
    set_config encrypted.map { |e| { 'secure' => e } }
    save_travis_config
  else
    list = encrypted.map { |data| format(data.inspect, "  secure: %s") }
    say(list.join("\n"), template(__FILE__), :none)
  end
end