Class: Pod::Command::Spec::Edit
Class Method Summary
collapse
Instance Method Summary
collapse
#ensure_master_spec_repo_exists!, report_error, run
#config
Constructor Details
#initialize(argv) ⇒ Edit
Returns a new instance of Edit.
22
23
24
25
26
27
28
|
# File 'lib/cocoapods/command/spec/edit.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
.options ⇒ Object
15
16
17
18
19
20
|
# File 'lib/cocoapods/command/spec/edit.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
#exec_editor(*args) ⇒ Object
81
82
83
84
|
# File 'lib/cocoapods/command/spec/edit.rb', line 81
def exec_editor(*args)
return if args.to_s.empty?
safe_exec(which_editor, *args)
end
|
#run ⇒ Object
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/cocoapods/command/spec/edit.rb', line 36
def run
query = @use_regex ? @query : Regexp.escape(@query)
if @show_all
specs = get_path_of_spec(query, @show_all).split(/\n/)
message = "Which spec would you like to edit [1-#{specs.count}]? "
index = UI.choose_from_array(specs, message)
filepath = specs[index]
else
filepath = get_path_of_spec(query)
end
exec_editor(filepath.to_s) if File.exist? filepath
raise Informative, "#{ filepath } doesn't exist."
end
|
#safe_exec(cmd, *args) ⇒ Object
86
87
88
89
90
|
# File 'lib/cocoapods/command/spec/edit.rb', line 86
def safe_exec(cmd, *args)
exec('/bin/sh', '-i', '-c', cmd + ' "$@"', '--', *args)
end
|
#validate! ⇒ Object
30
31
32
33
34
|
# File 'lib/cocoapods/command/spec/edit.rb', line 30
def validate!
super
help! 'A podspec name is required.' unless @query
validate_regex!(@query) if @use_regex
end
|
#which(cmd) ⇒ Object
Looks up an executable in the search paths
Thank you homebrew
59
60
61
62
|
# File 'lib/cocoapods/command/spec/edit.rb', line 59
def which(cmd)
dir = ENV['PATH'].split(':').find { |p| File.executable? File.join(p, cmd) }
Pathname.new(File.join(dir, cmd)) unless dir.nil?
end
|
#which_editor ⇒ Object
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
# File 'lib/cocoapods/command/spec/edit.rb', line 64
def which_editor
editor = ENV['EDITOR']
return editor unless editor.nil?
return 'subl' if which 'subl'
return 'mate' if which 'mate'
return 'edit' if which 'edit'
return 'vim' if which 'vim'
raise Informative, "Failed to open editor. Set your 'EDITOR' environment variable."
end
|