Class: Fastlane::RearchiveHelper::PlistBuddy

Inherits:
Object
  • Object
show all
Defined in:
lib/fastlane/plugin/rearchive/helper/plist_buddy.rb

Instance Method Summary collapse

Constructor Details

#initialize(plist_path) ⇒ PlistBuddy

Returns a new instance of PlistBuddy.



6
7
8
# File 'lib/fastlane/plugin/rearchive/helper/plist_buddy.rb', line 6

def initialize(plist_path)
  @plist_path = plist_path
end

Instance Method Details

#exec(command) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/fastlane/plugin/rearchive/helper/plist_buddy.rb', line 10

def exec(command)
  FastlaneCore::UI.verbose("/usr/libexec/PlistBuddy -c \"#{command}\" \"#{@plist_path}\"")
  result = IO.popen("/usr/libexec/PlistBuddy -c \"#{command}\" \"#{@plist_path}\"", &:read).gsub(/\A\s*"?|"?\s*\z/m, "")

  if $?.exitstatus.nonzero?
    FastlaneCore::UI.important("PlistBuddy command failed: #{result}")
    raise "PlistBuddy command failed failed with exit code #{$?.exitstatus} - #{result}"
  end

  return result
end

#parse_dict_keys(entry) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/fastlane/plugin/rearchive/helper/plist_buddy.rb', line 45

def parse_dict_keys(entry)
  # This should probably use -x and parse the xml using Nokogiri

  result_lines = entry.lines.map(&:chop)

  case RUBY_PLATFORM
  when "x86_64-linux", "aarch64-linux-gnu"
    raise "value is not an dict (#{RUBY_PLATFORM}): #{result_lines}" unless result_lines.first == "{"

    result_lines.map do |line|
      line.match(/(?<=^\t)[^\s}]+/)
    end
  else
    raise "value is not an dict (#{RUBY_PLATFORM}): #{result_lines}" unless result_lines.first == "Dict {"

    result_lines.map do |line|
      line.match(/(?<=^\s{4})[^\s}]+/)
    end
  end.compact.map(&:to_s)
end

#parse_scalar_array(result) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/fastlane/plugin/rearchive/helper/plist_buddy.rb', line 22

def parse_scalar_array(result)
  # This should probably use -x and parse the xml using Nokogiri

  return [] unless result =~ /\S/

  result_lines = result.lines.map(&:chop)

  case RUBY_PLATFORM
  when "x86_64-linux", "aarch64-linux-gnu"
    raise "value is not an array (#{RUBY_PLATFORM}): #{result_lines}" unless result_lines.first == "("

    result_lines.drop(1).take(result_lines.size - 2).map do |line|
      line[1..line.size].sub(/,$/, "")
    end
  else
    raise "value is not an array (#{RUBY_PLATFORM}): #{result_lines}" unless result_lines.first == "Array {"

    result_lines.drop(1).take(result_lines.size - 2).map do |line|
      line[4..line.size]
    end
  end
end