Class: MacSetup::Shell

Inherits:
Object
  • Object
show all
Defined in:
lib/mac_setup/shell.rb

Class Method Summary collapse

Class Method Details

.ask(question) ⇒ Object



20
21
22
23
# File 'lib/mac_setup/shell.rb', line 20

def ask(question)
  puts question
  STDIN.gets.strip
end

.command_present?(command) ⇒ Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/mac_setup/shell.rb', line 34

def command_present?(command)
  success?("command -v #{command} >/dev/null 2>&1")
end

.passwordObject



25
26
27
28
# File 'lib/mac_setup/shell.rb', line 25

def password
  puts "Enter Password"
  STDIN.noecho(&:gets).strip
end

.raw(command) ⇒ Object



16
17
18
# File 'lib/mac_setup/shell.rb', line 16

def raw(command)
  system(command)
end

.result(*command) ⇒ Object



8
9
10
# File 'lib/mac_setup/shell.rb', line 8

def result(*command)
  run(*command).output
end

.run(*command) ⇒ Object



12
13
14
# File 'lib/mac_setup/shell.rb', line 12

def run(*command)
  Result.new(*Open3.capture3(*command))
end

.sanitize_command(command) ⇒ Object



38
39
40
41
42
43
44
# File 'lib/mac_setup/shell.rb', line 38

def sanitize_command(command)
  if command.respond_to?(:each)
    Shellwords.join(command)
  else
    command
  end
end

.success?(command) ⇒ Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/mac_setup/shell.rb', line 30

def success?(command)
  run(command).success?
end