Class: Pod::Command::Bin::Open
Class Method Summary
collapse
Instance Method Summary
collapse
#validate!
#binary_spec, #binary_spec_files, #binary_template_spec, #binary_template_spec_file, #binary_template_spec_files, #clear_binary_spec_file_if_needed, #code_spec, #code_spec_files, #create_binary_spec_file, #find_spec_file, #spec_files
#binary_source, #code_source, #sources_manager, #sources_option, #valid_sources
Constructor Details
#initialize(argv) ⇒ Open
Returns a new instance of Open.
17
18
19
20
21
22
|
# File 'lib/cocoapods-bin/command/bin/open.rb', line 17
def initialize(argv)
@install = argv.flag?('install')
@update = argv.flag?('update')
@deep = argv.option('deep').try(:to_i) || 3
super
end
|
Class Method Details
.options ⇒ Object
9
10
11
12
13
14
15
|
# File 'lib/cocoapods-bin/command/bin/open.rb', line 9
def self.options
[
['--install', '先执行 install, 再执行 open. 相当于 pod install && pod bin open'],
['--update', '先执行 update, 再执行 open. 相当于 pod update && pod bin open'],
['--deep=5', '查找深度.']
]
end
|
Instance Method Details
#find_in_children(paths, deep) ⇒ Object
41
42
43
44
45
46
47
48
|
# File 'lib/cocoapods-bin/command/bin/open.rb', line 41
def find_in_children(paths, deep)
deep -= 1
pathname = paths.find { |ph| ph.extname == '.xcworkspace' }
return pathname if pathname || paths.empty? || deep <= 0
find_in_children(paths.select(&:directory?).flat_map(&:children), deep)
end
|
#find_in_parent(path, deep) ⇒ Object
50
51
52
53
54
55
56
57
|
# File 'lib/cocoapods-bin/command/bin/open.rb', line 50
def find_in_parent(path, deep)
deep -= 1
pathname = path.children.find { |fn| fn.extname == '.xcworkspace' }
return pathname if pathname || deep <= 0
find_in_parent(path.parent, deep)
end
|
#run ⇒ Object
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/cocoapods-bin/command/bin/open.rb', line 24
def run
if @install || @update
command_class = Object.const_get("Pod::Command::#{@install ? 'Install' : 'Update'}")
command = command_class.new(CLAide::ARGV.new([]))
command.validate!
command.run
end
path = find_in_children(Pathname.pwd.children, @deep) ||
find_in_parent(Pathname.pwd.parent, @deep)
if path
`open #{path}`
else
UI.puts "#{Pathname.pwd} 目录, 搜索上下深度 #{@deep} , 无法找到 xcworkspace 文件.".red
end
end
|