Class: Xcodeproj::Command::Show

Inherits:
Xcodeproj::Command show all
Defined in:
lib/xcodeproj/command/show.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ Show

Returns a new instance of Show.


16
17
18
19
20
21
# File 'lib/xcodeproj/command/show.rb', line 16

def initialize(argv)
  self.xcodeproj_path = argv.shift_argument
  @output_format = argv.option('format')
  @output_format &&= @output_format.to_sym
  super
end

Class Method Details

.optionsObject


6
7
8
9
10
# File 'lib/xcodeproj/command/show.rb', line 6

def self.options
  [
    ['--format=[hash|tree_hash|raw]', 'YAML output format'],
  ].concat(super)
end

Instance Method Details

#runObject


31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/xcodeproj/command/show.rb', line 31

def run
  require 'yaml'

  if @output_format
    case @output_format
    when :hash
      puts xcodeproj.to_hash.to_yaml
    when :tree_hash
      puts xcodeproj.to_tree_hash.to_yaml
    when :raw
      puts xcodeproj.to_yaml
    end
    return
  end

  pretty_print = xcodeproj.pretty_print
  sections = []
  pretty_print.each do |key, value|
    section = key.green
    yaml = value.to_yaml
    yaml.gsub!(/^---$/, '')
    yaml.gsub!(/^-/, "\n-")
    yaml.prepend(section)
    sections << yaml
  end
  puts sections * "\n\n"
end

#validateObject


23
24
25
26
27
28
29
# File 'lib/xcodeproj/command/show.rb', line 23

def validate
  super
  unless [nil, :hash, :tree_hash, :raw].include?(@output_format)
    help! "Unknown format `#{@output_format}`"
  end
  open_project!
end