Class: Dru::Command
- Inherits:
-
Object
- Object
- Dru::Command
- Extended by:
- Forwardable
- Defined in:
- lib/dru/command.rb
Direct Known Subclasses
Dru::Commands::DockerCompose, Dru::Commands::Down, Dru::Commands::Up, ContainerCommand
Defined Under Namespace
Classes: MissingContainerError
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.
15 16 17 |
# File 'lib/dru/command.rb', line 15 def @options end |
Instance Method Details
#command(**options) ⇒ Object
The external commands runner
34 35 36 37 |
# File 'lib/dru/command.rb', line 34 def command(**) require 'tty-command' TTY::Command.new({ printer: :quiet, uuid: false }.merge()) end |
#container_name_to_id(container_name = 'app') ⇒ Object
163 164 165 |
# File 'lib/dru/command.rb', line 163 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
44 45 46 47 |
# File 'lib/dru/command.rb', line 44 def cursor require 'tty-cursor' TTY::Cursor end |
#default_docker_compose ⇒ Object
141 142 143 |
# File 'lib/dru/command.rb', line 141 def default_docker_compose File.join(project_configuration_path, 'docker-compose.yml') end |
#docker_compose_paths ⇒ Object
151 152 153 |
# File 'lib/dru/command.rb', line 151 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
54 55 56 57 |
# File 'lib/dru/command.rb', line 54 def editor require 'tty-editor' TTY::Editor end |
#environment ⇒ Object
133 134 135 |
# File 'lib/dru/command.rb', line 133 def environment && [:environment] end |
#environment_docker_compose ⇒ Object
145 146 147 148 149 |
# File 'lib/dru/command.rb', line 145 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
124 125 126 127 |
# File 'lib/dru/command.rb', line 124 def exec_exist?(*args) require 'tty-which' TTY::Which.exist?(*args) end |
#execute ⇒ Object
Execute this command
22 23 24 25 26 27 |
# File 'lib/dru/command.rb', line 22 def execute(*) raise( NotImplementedError, "#{self.class}##{__method__} must be implemented" ) end |
#generator ⇒ Object
File manipulation utility methods
64 65 66 67 |
# File 'lib/dru/command.rb', line 64 def generator require 'tty-file' TTY::File end |
#pager(**options) ⇒ Object
Terminal output paging
74 75 76 77 |
# File 'lib/dru/command.rb', line 74 def pager(**) require 'tty-pager' TTY::Pager.new() end |
#platform ⇒ Object
Terminal platform and OS properties
84 85 86 87 |
# File 'lib/dru/command.rb', line 84 def platform require 'tty-platform' TTY::Platform.new end |
#project_configuration_path ⇒ Object
137 138 139 |
# File 'lib/dru/command.rb', line 137 def project_configuration_path File.(project_name, Dru.config.docker_projects_folder) end |
#project_name ⇒ Object
129 130 131 |
# File 'lib/dru/command.rb', line 129 def project_name File.basename(Dir.pwd) end |
#prompt(**options) ⇒ Object
The interactive prompt
94 95 96 97 |
# File 'lib/dru/command.rb', line 94 def prompt(**) require 'tty-prompt' TTY::Prompt.new() end |
#run_docker_compose_command(*args, **options) ⇒ Object
155 156 157 158 159 160 161 |
# File 'lib/dru/command.rb', line 155 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
104 105 106 107 |
# File 'lib/dru/command.rb', line 104 def screen require 'tty-screen' TTY::Screen end |
#which(*args) ⇒ Object
The unix which utility
114 115 116 117 |
# File 'lib/dru/command.rb', line 114 def which(*args) require 'tty-which' TTY::Which.which(*args) end |