Class: Dru::Command
- Inherits:
-
Object
- Object
- Dru::Command
- Extended by:
- Forwardable
- Defined in:
- lib/dru/command.rb
Direct Known Subclasses
Defined Under Namespace
Classes: MissingContainerError
Constant Summary collapse
- DOCKER_COMPOSE_COMMAND =
'docker-compose'.freeze
Instance Attribute Summary collapse
-
#options ⇒ Object
Returns the value of attribute options.
Instance Method Summary collapse
-
#command(**options) ⇒ Object
The external commands runner.
- #container_name_to_id(container_name = 'app') ⇒ Object
-
#cursor ⇒ Object
The cursor movement.
- #default_docker_compose ⇒ Object
- #docker_compose_paths ⇒ Object
-
#editor ⇒ Object
Open a file or text in the user’s preferred editor.
- #environment ⇒ Object
- #environment_docker_compose ⇒ Object
-
#exec_exist?(*args) ⇒ Boolean
Check if executable exists.
-
#execute ⇒ Object
Execute this command.
-
#generator ⇒ Object
File manipulation utility methods.
-
#pager(**options) ⇒ Object
Terminal output paging.
-
#platform ⇒ Object
Terminal platform and OS properties.
- #project_configuration_path ⇒ Object
- #project_name ⇒ Object
-
#prompt(**options) ⇒ Object
The interactive prompt.
- #run_docker_compose_command(*args, **options) ⇒ Object
-
#screen ⇒ Object
Get terminal screen properties.
-
#which(*args) ⇒ Object
The unix which utility.
Instance Attribute Details
#options ⇒ Object
Returns the value of attribute options.
17 18 19 |
# File 'lib/dru/command.rb', line 17 def @options end |
Instance Method Details
#command(**options) ⇒ Object
The external commands runner
36 37 38 39 |
# File 'lib/dru/command.rb', line 36 def command(**) require 'tty-command' TTY::Command.new({ printer: :quiet, uuid: false }.merge()) end |
#container_name_to_id(container_name = 'app') ⇒ Object
165 166 167 |
# File 'lib/dru/command.rb', line 165 def container_name_to_id(container_name = 'app') run_docker_compose_command('ps', '-q', container_name, printer: :null).first end |
#cursor ⇒ Object
The cursor movement
46 47 48 49 |
# File 'lib/dru/command.rb', line 46 def cursor require 'tty-cursor' TTY::Cursor end |
#default_docker_compose ⇒ Object
143 144 145 |
# File 'lib/dru/command.rb', line 143 def default_docker_compose File.join(project_configuration_path, 'docker-compose.yml') end |
#docker_compose_paths ⇒ Object
153 154 155 |
# File 'lib/dru/command.rb', line 153 def docker_compose_paths docker_compose_default_path + docker_compose_environment_path end |
#editor ⇒ Object
Open a file or text in the user’s preferred editor
56 57 58 59 |
# File 'lib/dru/command.rb', line 56 def editor require 'tty-editor' TTY::Editor end |
#environment ⇒ Object
135 136 137 |
# File 'lib/dru/command.rb', line 135 def environment && [:environment] end |
#environment_docker_compose ⇒ Object
147 148 149 150 151 |
# File 'lib/dru/command.rb', line 147 def environment_docker_compose return unless environment File.join(project_configuration_path, "docker-compose.#{environment}.yml") end |
#exec_exist?(*args) ⇒ Boolean
Check if executable exists
126 127 128 129 |
# File 'lib/dru/command.rb', line 126 def exec_exist?(*args) require 'tty-which' TTY::Which.exist?(*args) end |
#execute ⇒ Object
Execute this command
24 25 26 27 28 29 |
# File 'lib/dru/command.rb', line 24 def execute(*) raise( NotImplementedError, "#{self.class}##{__method__} must be implemented" ) end |
#generator ⇒ Object
File manipulation utility methods
66 67 68 69 |
# File 'lib/dru/command.rb', line 66 def generator require 'tty-file' TTY::File end |
#pager(**options) ⇒ Object
Terminal output paging
76 77 78 79 |
# File 'lib/dru/command.rb', line 76 def pager(**) require 'tty-pager' TTY::Pager.new() end |
#platform ⇒ Object
Terminal platform and OS properties
86 87 88 89 |
# File 'lib/dru/command.rb', line 86 def platform require 'tty-platform' TTY::Platform.new end |
#project_configuration_path ⇒ Object
139 140 141 |
# File 'lib/dru/command.rb', line 139 def project_configuration_path File.(project_name, Dru.config.docker_projects_folder) end |
#project_name ⇒ Object
131 132 133 |
# File 'lib/dru/command.rb', line 131 def project_name File.basename(Dir.pwd) end |
#prompt(**options) ⇒ Object
The interactive prompt
96 97 98 99 |
# File 'lib/dru/command.rb', line 96 def prompt(**) require 'tty-prompt' TTY::Prompt.new() end |
#run_docker_compose_command(*args, **options) ⇒ Object
157 158 159 160 161 162 163 |
# File 'lib/dru/command.rb', line 157 def run_docker_compose_command(*args, **) if [:tty] system(DOCKER_COMPOSE_COMMAND, *docker_compose_paths, *args) else command().run(DOCKER_COMPOSE_COMMAND, *docker_compose_paths, *args) end end |
#screen ⇒ Object
Get terminal screen properties
106 107 108 109 |
# File 'lib/dru/command.rb', line 106 def screen require 'tty-screen' TTY::Screen end |
#which(*args) ⇒ Object
The unix which utility
116 117 118 119 |
# File 'lib/dru/command.rb', line 116 def which(*args) require 'tty-which' TTY::Which.which(*args) end |