Module: Licensed::Shell
- Defined in:
- lib/licensed/shell.rb
Class Method Summary collapse
-
.execute(cmd, *args) ⇒ Object
Executes a command, returning it’s STDOUT on success.
-
.success?(cmd, *args) ⇒ Boolean
Executes a command and returns a boolean value indicating if the command was succesful.
-
.tool_available?(tool) ⇒ Boolean
Returns a boolean indicating whether a CLI tool is available in the current environment.
Class Method Details
.execute(cmd, *args) ⇒ Object
Executes a command, returning it’s STDOUT on success. Returns an empty string on failure
8 9 10 11 12 |
# File 'lib/licensed/shell.rb', line 8 def self.execute(cmd, *args) output, _, status = Open3.capture3(cmd, *args) return "" unless status.success? output.strip end |
.success?(cmd, *args) ⇒ Boolean
Executes a command and returns a boolean value indicating if the command was succesful
16 17 18 19 |
# File 'lib/licensed/shell.rb', line 16 def self.success?(cmd, *args) _, _, status = Open3.capture3(cmd, *args) status.success? end |
.tool_available?(tool) ⇒ Boolean
Returns a boolean indicating whether a CLI tool is available in the current environment
23 24 25 26 |
# File 'lib/licensed/shell.rb', line 23 def self.tool_available?(tool) output, err, status = Open3.capture3("which", tool) status.success? && !output.strip.empty? && err.strip.empty? end |