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



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

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

.command_present?(command) ⇒ Boolean

Returns:

  • (Boolean)


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

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

.passwordObject



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

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

.raw(command) ⇒ Object



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

def raw(command)
  system(command)
end

.run(command) ⇒ Object



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

def run(command)
  `#{sanitize_command(command)}`
end

.sanitize_command(command) ⇒ Object



33
34
35
36
37
38
39
# File 'lib/mac_setup/shell.rb', line 33

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

.success?(command) ⇒ Boolean

Returns:

  • (Boolean)


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

def success?(command)
  system(sanitize_command(command))
end