Module: Geet::Helpers::OsHelper
- Extended by:
- T::Sig
- Includes:
- Kernel
- Included in:
- Commandline::Editor, Services::CommentPr, Services::CreateGist, Services::CreateIssue, Services::CreatePr, Services::OpenPr, Services::OpenRepo, Utils::GitClient
- Defined in:
- lib/geet/helpers/os_helper.rb
Instance Method Summary collapse
- #execute_command(command, description: nil, interactive: false, silent_stderr: false, allow_error: false) ⇒ Object
- #open_file_with_default_application(file_or_url) ⇒ Object
Instance Method Details
#execute_command(command, description: nil, interactive: false, silent_stderr: false, allow_error: false) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/geet/helpers/os_helper.rb', line 48 def execute_command(command, description: nil, interactive: false, silent_stderr: false, allow_error: false) = " on #{description}" if description if interactive system(command) if !$CHILD_STATUS.success? && !allow_error raise "Error#{} (exit status: #{$CHILD_STATUS.exitstatus})" end else result = "" Open3.popen3(command) do |_, stdout, stderr, wait_thread| stdout_content = stdout.read stderr_content = stderr.read puts stderr_content if stderr_content != "" && !silent_stderr if !wait_thread.value.success? && !allow_error = stderr_content.lines.first&.strip || "Error running command #{command.inspect}" raise "Error#{}: #{}" end result = stdout_content.strip end result end end |
#open_file_with_default_application(file_or_url) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/geet/helpers/os_helper.rb', line 16 def open_file_with_default_application(file_or_url) open_command = case when ENV["WSL_DISTRO_NAME"] "wslview" when `uname`.strip == "Darwin" "open" else "xdg-open" end command = "#{open_command} #{file_or_url.shellescape}" system(command, exception: true) end |