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(color = :blue) ⇒ Trent
constructor
A new instance of Trent.
-
#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(color = :blue) ⇒ Trent
Returns a new instance of Trent.
12 13 14 15 16 17 18 19 |
# File 'lib/trent.rb', line 12 def initialize(color = :blue) Log.fatal('Trent is designed to run on Travis-CI builds. Run it on Travis-CI.') unless ENV['HAS_JOSH_K_SEAL_OF_APPROVAL'] @color = color @sh = Sh.new @paths = {} end |
Instance Method Details
#config_github(api_key) ⇒ Object
Configure how to communicate with GitHub
27 28 29 |
# File 'lib/trent.rb', line 27 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.
22 23 24 |
# File 'lib/trent.rb', line 22 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
65 66 67 68 |
# File 'lib/trent.rb', line 65 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.
36 37 38 |
# File 'lib/trent.rb', line 36 def path(command, path) @paths[command] = path end |
#sh(command, fail_non_success: true) ⇒ Object
Run local bash command
54 55 56 57 58 59 60 61 62 |
# File 'lib/trent.rb', line 54 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
41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/trent.rb', line 41 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 |