Class: Devbin::Command
- Inherits:
-
Object
- Object
- Devbin::Command
- Extended by:
- Forwardable
- Defined in:
- lib/devbin/command.rb
Direct Known Subclasses
Devbin::Commands::Rails::Attach, Devbin::Commands::Rails::Console, Devbin::Commands::Rails::Off, Devbin::Commands::Rails::Restart, Devbin::Commands::Rails::Server, Devbin::Commands::Rails::Stop
Instance Method Summary collapse
-
#command(**options) ⇒ Object
The external commands runner.
-
#cursor ⇒ Object
The cursor movement.
- #docker_pwd ⇒ Object
- #docker_sync_pwd ⇒ Object
-
#editor ⇒ Object
Open a file or text in the user’s preferred editor.
-
#exec_exist?(*args) ⇒ Boolean
Check if executable exists.
-
#execute ⇒ Object
Execute this command.
- #find_pwd(file_or_directory_name) ⇒ Object
-
#generator ⇒ Object
File manipulation utility methods.
-
#pager(**options) ⇒ Object
Terminal output paging.
- #pastel ⇒ Object
-
#platform ⇒ Object
Terminal platform and OS properties.
-
#prompt(**options) ⇒ Object
The interactive prompt.
-
#screen ⇒ Object
Get terminal screen properties.
-
#which(*args) ⇒ Object
The unix which utility.
Instance Method Details
#command(**options) ⇒ Object
The external commands runner
26 27 28 29 |
# File 'lib/devbin/command.rb', line 26 def command(**) require "tty-command" TTY::Command.new() end |
#cursor ⇒ Object
The cursor movement
36 37 38 39 |
# File 'lib/devbin/command.rb', line 36 def cursor require "tty-cursor" TTY::Cursor end |
#docker_pwd ⇒ Object
155 156 157 158 159 160 161 162 163 164 |
# File 'lib/devbin/command.rb', line 155 def docker_pwd @docker_pwd ||= begin path = find_pwd("docker") if path.empty? fail "Cannot find the `docker' folder" end path.push("docker").join("/") end end |
#docker_sync_pwd ⇒ Object
144 145 146 147 148 149 150 151 152 153 |
# File 'lib/devbin/command.rb', line 144 def docker_sync_pwd @docker_sync_pwd ||= begin path = find_pwd("docker-sync.yml") if path.empty? fail "Cannot find the `docker-sync.yml' file" end path.join("/") end end |
#editor ⇒ Object
Open a file or text in the user’s preferred editor
46 47 48 49 |
# File 'lib/devbin/command.rb', line 46 def editor require "tty-editor" TTY::Editor end |
#exec_exist?(*args) ⇒ Boolean
Check if executable exists
116 117 118 119 |
# File 'lib/devbin/command.rb', line 116 def exec_exist?(*args) require "tty-which" TTY::Which.exist?(*args) end |
#execute ⇒ Object
Execute this command
14 15 16 17 18 19 |
# File 'lib/devbin/command.rb', line 14 def execute(*) raise( NotImplementedError, "#{self.class}##{__method__} must be implemented" ) end |
#find_pwd(file_or_directory_name) ⇒ Object
129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/devbin/command.rb', line 129 def find_pwd(file_or_directory_name) path = [".", file_or_directory_name] file = nil results = Dir[path.join("/")] file = results[0] return path[0..-2] unless results.empty? 3.times do path.unshift("..") results = Dir[path.join("/")] file = results[0] return path[0..-2] unless results.empty? end [] end |
#generator ⇒ Object
File manipulation utility methods
56 57 58 59 |
# File 'lib/devbin/command.rb', line 56 def generator require "tty-file" TTY::File end |
#pager(**options) ⇒ Object
Terminal output paging
66 67 68 69 |
# File 'lib/devbin/command.rb', line 66 def pager(**) require "tty-pager" TTY::Pager.new() end |
#pastel ⇒ Object
121 122 123 124 125 126 127 |
# File 'lib/devbin/command.rb', line 121 def pastel @pastel ||= begin require "pastel" Pastel.new end end |
#platform ⇒ Object
Terminal platform and OS properties
76 77 78 79 |
# File 'lib/devbin/command.rb', line 76 def platform require "tty-platform" TTY::Platform.new end |
#prompt(**options) ⇒ Object
The interactive prompt
86 87 88 89 |
# File 'lib/devbin/command.rb', line 86 def prompt(**) require "tty-prompt" TTY::Prompt.new() end |
#screen ⇒ Object
Get terminal screen properties
96 97 98 99 |
# File 'lib/devbin/command.rb', line 96 def screen require "tty-screen" TTY::Screen end |
#which(*args) ⇒ Object
The unix which utility
106 107 108 109 |
# File 'lib/devbin/command.rb', line 106 def which(*args) require "tty-which" TTY::Which.which(*args) end |