Class: Trent
- Inherits:
-
Object
- Object
- Trent
- Defined in:
- lib/trent.rb
Overview
Communicate with all of the Trent library with this class.
Instance Method Summary collapse
-
#config_github(api_key) ⇒ Object
Configure how to communicate with GitHub.
-
#config_ssh(username, host, password = nil) ⇒ Object
Configure how to run remote SSH commmands on server.
-
#github ⇒ Object
Get instance of GitHub class to run commands against GitHub.
-
#initialize(params = {}) ⇒ Trent
constructor
Initialize Trent instance.
-
#path(command, path) ⇒ Object
While working with bash commands, some commands are not added to the path.
-
#sh(command, fail_non_success: true) ⇒ Object
Run local bash command.
-
#ssh(command, fail_non_success: true) ⇒ Object
Run ssh command.
Constructor Details
#initialize(params = {}) ⇒ Trent
Initialize Trent instance. color - Color of shell output you want Trent to use. local - Run Trent locally on your own machine instead of a CI server.
15 16 17 18 19 20 21 22 23 |
# File 'lib/trent.rb', line 15 def initialize(params = {}) running_local = params.fetch(:local, false) Log.fatal('Trent is designed to run on Travis-CI builds. Run it on Travis-CI.') unless ENV['HAS_JOSH_K_SEAL_OF_APPROVAL'] || running_local @color = params.fetch(:color, :blue) @sh = Sh.new @paths = {} end |
Instance Method Details
#config_github(api_key) ⇒ Object
Configure how to communicate with GitHub
31 32 33 |
# File 'lib/trent.rb', line 31 def config_github(api_key) @github = GitHub.new(api_key) end |
#config_ssh(username, host, password = nil) ⇒ Object
Configure how to run remote SSH commmands on server.
26 27 28 |
# File 'lib/trent.rb', line 26 def config_ssh(username, host, password = nil) @ssh = SSH.new(username, host, password: password) end |
#github ⇒ Object
Get instance of GitHub class to run commands against GitHub
69 70 71 72 |
# File 'lib/trent.rb', line 69 def github Log.fatal('You did not configure GitHub yet.') unless @github @github end |
#path(command, path) ⇒ Object
While working with bash commands, some commands are not added to the path. That’s annoying. Convenient method to assign a command to a path for replacing. Example: ci.path(“docker-compose”, “/opt/bin/docker-compose”) Now, when you use ci.sh(“docker-compose -f … up -d”), it will run “/opt/bin/docker-compose -f … up -d” instead.
40 41 42 |
# File 'lib/trent.rb', line 40 def path(command, path) @paths[command] = path end |
#sh(command, fail_non_success: true) ⇒ Object
Run local bash command
58 59 60 61 62 63 64 65 66 |
# File 'lib/trent.rb', line 58 def sh(command, fail_non_success: true) command = Command.path_replace(command, @paths) puts command.colorize(@color) result = @sh.run(command) process_shell_result(result, fail_non_success) result end |
#ssh(command, fail_non_success: true) ⇒ Object
Run ssh command
45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/trent.rb', line 45 def ssh(command, fail_non_success: true) command = Command.path_replace(command, @paths) Log.fatal('You did not configure SSH yet.') unless @ssh puts command.colorize(@color) result = @ssh.run(command) process_shell_result(result, fail_non_success) result end |