Class: GithubCLI::System

Inherits:
Object
  • Object
show all
Defined in:
lib/github_cli/system.rb

Overview

This class provides methods for reading system settings.

Class Method Summary collapse

Class Method Details

.command?(name) ⇒ Boolean

Checks if command exists.

Returns:

  • (Boolean)


27
28
29
# File 'lib/github_cli/system.rb', line 27

def command?(name)
  !which(name).nil?
end

.which(command) ⇒ Object

Finds executable in $PATH.



15
16
17
18
19
20
21
22
23
24
# File 'lib/github_cli/system.rb', line 15

def which(command)
  exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
  ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
    exts.each do |ext|
      exe = "#{path}/#{command}#{ext}"
      return exe if File.executable? exe
    end
  end
  return nil
end

.windows?Boolean

Checks if windows platform.

Returns:

  • (Boolean)


9
10
11
12
# File 'lib/github_cli/system.rb', line 9

def windows?
  require 'rbconfig'
  RbConfig::CONFIG['host_os'] =~ /msdos|mswin|djgpp|mingw|windows/
end