Module: Pindo::Plistbuddyexecutable

Included in:
Command::Deploy::Resign
Defined in:
lib/pindo/base/plistbuddyexecutable.rb

Defined Under Namespace

Classes: Plistbuddyindenter

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.plistbuddy_execute_command(executable, command, raise_on_failure = true) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/pindo/base/plistbuddyexecutable.rb', line 16

def self.plistbuddy_execute_command(executable, command, raise_on_failure = true)
  bin = '/usr/libexec/PlistBuddy'

  command = command.map(&:to_s)
  full_command = "#{bin} #{command.join(' ')}"

  
  puts "$ #{full_command}" 
  stdout = Plistbuddyindenter.new(STDOUT)
  stderr = Plistbuddyindenter.new(STDERR)


  status = plistbuddy_popen3(bin, command, stdout, stderr)
  stdout = stdout.join
  stderr = stderr.join
  output = stdout + stderr
  unless status.success?
    if raise_on_failure
      raise  Informative, "#{full_command}\n\n#{output}"
    else
      puts "[!] Failed: #{full_command}"
    end
  end

  output
end

Instance Method Details

#plistbuddyexecutable(name) ⇒ Object



5
6
7
8
9
10
11
12
13
# File 'lib/pindo/base/plistbuddyexecutable.rb', line 5

def plistbuddyexecutable(name)
  define_method(name) do |*command|
    Plistbuddyexecutable.plistbuddy_execute_command(name, Array(command).flatten, false)
  end

  define_method(name.to_s + '!') do |*command|
    Plistbuddyexecutable.plistbuddy_execute_command(name, Array(command).flatten, true)
  end
end