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=, #api_endpoint, #api_endpoint=, #artifact, #build, #explicit_api_endpoint?, #github_auth, #job, #repo, #repos, #restart, #user, #worker, #workers

Methods inherited from Command

abstract, abstract?, command_name, #command_name, #debug, #execute, #help, #initialize, #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



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/travis/cli/encrypt.rb', line 16

def run(*args)
  if args.first =~ %r{\w+/\w+}
    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 } }
    File.write(travis_yaml, travis_config.to_yaml)
  else
    list = encrypted.map { |data| format(data.inspect, "  secure: %s") }
    say(list.join("\n"), template(__FILE__), :none)
  end
end