Class: Pod::Command::Spec::Cat

Inherits:
Pod::Command::Spec show all
Defined in:
lib/cocoapods/command/spec/cat.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Pod::Command

#ensure_master_spec_repo_exists!, report_error, run

Methods included from Pod::Config::Mixin

#config

Constructor Details

#initialize(argv) ⇒ Cat

Returns a new instance of Cat.



22
23
24
25
26
27
28
# File 'lib/cocoapods/command/spec/cat.rb', line 22

def initialize(argv)
  @use_regex = argv.flag?('regex')
  @show_all = argv.flag?('show-all')
  @query = argv.shift_argument
  @query = @query.gsub('.podspec', '') unless @query.nil?
  super
end

Class Method Details

.optionsObject



15
16
17
18
19
20
# File 'lib/cocoapods/command/spec/cat.rb', line 15

def self.options
  [
    ['--regex', 'Interpret the `QUERY` as a regular expression'],
    ['--show-all', 'Pick from all versions of the given podspec'],
  ].concat(super)
end

Instance Method Details

#runObject



36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/cocoapods/command/spec/cat.rb', line 36

def run
  query = @use_regex ? @query : Regexp.escape(@query)
  filepath = if @show_all
               specs = get_path_of_spec(query, @show_all).split(/\n/)
               index = UI.choose_from_array(specs, "Which spec would you like to print [1-#{ specs.count }]? ")
               specs[index]
             else
               get_path_of_spec(query)
             end

  UI.puts File.read(filepath)
end

#validate!Object



30
31
32
33
34
# File 'lib/cocoapods/command/spec/cat.rb', line 30

def validate!
  super
  help! 'A podspec name is required.' unless @query
  validate_regex!(@query) if @use_regex
end