cocoapods 0.39.0.beta.1 → 0.39.0.beta.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -0
- data/lib/cocoapods/gem_version.rb +1 -1
- metadata +35 -63
- data/lib/cocoapods/command/cache/clean.rb +0 -90
- data/lib/cocoapods/command/cache/list.rb +0 -69
- data/lib/cocoapods/command/repo/add.rb +0 -53
- data/lib/cocoapods/command/repo/lint.rb +0 -77
- data/lib/cocoapods/command/repo/list.rb +0 -93
- data/lib/cocoapods/command/repo/push.rb +0 -223
- data/lib/cocoapods/command/repo/remove.rb +0 -36
- data/lib/cocoapods/command/repo/update.rb +0 -27
- data/lib/cocoapods/command/spec/cat.rb +0 -51
- data/lib/cocoapods/command/spec/create.rb +0 -279
- data/lib/cocoapods/command/spec/edit.rb +0 -94
- data/lib/cocoapods/command/spec/lint.rb +0 -119
- data/lib/cocoapods/command/spec/which.rb +0 -43
- data/lib/cocoapods/generator/acknowledgements/markdown.rb +0 -38
- data/lib/cocoapods/generator/acknowledgements/plist.rb +0 -80
- data/lib/cocoapods/generator/xcconfig/aggregate_xcconfig.rb +0 -260
- data/lib/cocoapods/generator/xcconfig/pod_xcconfig.rb +0 -83
- data/lib/cocoapods/generator/xcconfig/xcconfig_helper.rb +0 -213
- data/lib/cocoapods/installer/analyzer/analysis_result.rb +0 -46
- data/lib/cocoapods/installer/analyzer/locking_dependency_analyzer.rb +0 -79
- data/lib/cocoapods/installer/analyzer/sandbox_analyzer.rb +0 -262
- data/lib/cocoapods/installer/analyzer/specs_state.rb +0 -76
- data/lib/cocoapods/installer/analyzer/target_inspection_result.rb +0 -41
- data/lib/cocoapods/installer/analyzer/target_inspector.rb +0 -203
- data/lib/cocoapods/installer/target_installer/aggregate_target_installer.rb +0 -186
- data/lib/cocoapods/installer/target_installer/pod_target_installer.rb +0 -297
- data/lib/cocoapods/installer/user_project_integrator/target_integrator.rb +0 -318
- data/lib/cocoapods/installer/user_project_integrator/target_integrator/xcconfig_integrator.rb +0 -173
@@ -1,36 +0,0 @@
|
|
1
|
-
module Pod
|
2
|
-
class Command
|
3
|
-
class Repo < Command
|
4
|
-
class Remove < Repo
|
5
|
-
self.summary = 'Remove a spec repo'
|
6
|
-
|
7
|
-
self.description = <<-DESC
|
8
|
-
Deletes the remote named `NAME` from the local spec-repos directory at `~/.cocoapods/repos/.`
|
9
|
-
DESC
|
10
|
-
|
11
|
-
self.arguments = [
|
12
|
-
CLAide::Argument.new('NAME', true),
|
13
|
-
]
|
14
|
-
|
15
|
-
def initialize(argv)
|
16
|
-
@name = argv.shift_argument
|
17
|
-
super
|
18
|
-
end
|
19
|
-
|
20
|
-
def validate!
|
21
|
-
super
|
22
|
-
help! 'Deleting a repo needs a `NAME`.' unless @name
|
23
|
-
help! "repo #{@name} does not exist" unless File.directory?(dir)
|
24
|
-
help! "You do not have permission to delete the #{@name} repository." \
|
25
|
-
'Perhaps try prefixing this command with sudo.' unless File.writable?(dir)
|
26
|
-
end
|
27
|
-
|
28
|
-
def run
|
29
|
-
UI.section("Removing spec repo `#{@name}`") do
|
30
|
-
FileUtils.rm_rf(dir)
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
@@ -1,27 +0,0 @@
|
|
1
|
-
module Pod
|
2
|
-
class Command
|
3
|
-
class Repo < Command
|
4
|
-
class Update < Repo
|
5
|
-
self.summary = 'Update a spec repo.'
|
6
|
-
|
7
|
-
self.description = <<-DESC
|
8
|
-
Updates the local clone of the spec-repo `NAME`. If `NAME` is omitted
|
9
|
-
this will update all spec-repos in `~/.cocoapods/repos`.
|
10
|
-
DESC
|
11
|
-
|
12
|
-
self.arguments = [
|
13
|
-
CLAide::Argument.new('NAME', false),
|
14
|
-
]
|
15
|
-
|
16
|
-
def initialize(argv)
|
17
|
-
@name = argv.shift_argument
|
18
|
-
super
|
19
|
-
end
|
20
|
-
|
21
|
-
def run
|
22
|
-
SourcesManager.update(@name, true)
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
@@ -1,51 +0,0 @@
|
|
1
|
-
module Pod
|
2
|
-
class Command
|
3
|
-
class Spec < Command
|
4
|
-
class Cat < Spec
|
5
|
-
self.summary = 'Prints a spec file.'
|
6
|
-
|
7
|
-
self.description = <<-DESC
|
8
|
-
Prints the content of the podspec(s) whose name matches `QUERY` to standard output.
|
9
|
-
DESC
|
10
|
-
|
11
|
-
self.arguments = [
|
12
|
-
CLAide::Argument.new('QUERY', false),
|
13
|
-
]
|
14
|
-
|
15
|
-
def self.options
|
16
|
-
[
|
17
|
-
['--regex', 'Interpret the `QUERY` as a regular expression'],
|
18
|
-
['--show-all', 'Pick from all versions of the given podspec'],
|
19
|
-
].concat(super)
|
20
|
-
end
|
21
|
-
|
22
|
-
def initialize(argv)
|
23
|
-
@use_regex = argv.flag?('regex')
|
24
|
-
@show_all = argv.flag?('show-all')
|
25
|
-
@query = argv.shift_argument
|
26
|
-
@query = @query.gsub('.podspec', '') unless @query.nil?
|
27
|
-
super
|
28
|
-
end
|
29
|
-
|
30
|
-
def validate!
|
31
|
-
super
|
32
|
-
help! 'A podspec name is required.' unless @query
|
33
|
-
validate_regex!(@query) if @use_regex
|
34
|
-
end
|
35
|
-
|
36
|
-
def run
|
37
|
-
query = @use_regex ? @query : Regexp.escape(@query)
|
38
|
-
filepath = if @show_all
|
39
|
-
specs = get_path_of_spec(query, @show_all).split(/\n/)
|
40
|
-
index = UI.choose_from_array(specs, "Which spec would you like to print [1-#{ specs.count }]? ")
|
41
|
-
specs[index]
|
42
|
-
else
|
43
|
-
get_path_of_spec(query)
|
44
|
-
end
|
45
|
-
|
46
|
-
UI.puts File.read(filepath)
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
@@ -1,279 +0,0 @@
|
|
1
|
-
|
2
|
-
module Pod
|
3
|
-
class Command
|
4
|
-
class Spec < Command
|
5
|
-
class Create < Spec
|
6
|
-
self.summary = 'Create spec file stub.'
|
7
|
-
|
8
|
-
self.description = <<-DESC
|
9
|
-
Creates a PodSpec, in the current working dir, called `NAME.podspec'.
|
10
|
-
If a GitHub url is passed the spec is prepopulated.
|
11
|
-
DESC
|
12
|
-
|
13
|
-
self.arguments = [
|
14
|
-
CLAide::Argument.new(%w(NAME https://github.com/USER/REPO), false),
|
15
|
-
]
|
16
|
-
|
17
|
-
def initialize(argv)
|
18
|
-
@name_or_url, @url = argv.shift_argument, argv.shift_argument
|
19
|
-
super
|
20
|
-
end
|
21
|
-
|
22
|
-
def validate!
|
23
|
-
super
|
24
|
-
help! 'A pod name or repo URL is required.' unless @name_or_url
|
25
|
-
end
|
26
|
-
|
27
|
-
def run
|
28
|
-
if repo_id_match = (@url || @name_or_url).match(%r{github.com/([^/\.]*\/[^/\.]*)\.*})
|
29
|
-
repo_id = repo_id_match[1]
|
30
|
-
data = github_data_for_template(repo_id)
|
31
|
-
data[:name] = @name_or_url if @url
|
32
|
-
UI.puts semantic_versioning_notice(repo_id, data[:name]) if data[:version] == '0.0.1'
|
33
|
-
else
|
34
|
-
data = default_data_for_template(@name_or_url)
|
35
|
-
end
|
36
|
-
|
37
|
-
spec = spec_template(data)
|
38
|
-
(Pathname.pwd + "#{data[:name]}.podspec").open('w') { |f| f << spec }
|
39
|
-
UI.puts "\nSpecification created at #{data[:name]}.podspec".green
|
40
|
-
end
|
41
|
-
|
42
|
-
private
|
43
|
-
|
44
|
-
#--------------------------------------#
|
45
|
-
|
46
|
-
# Templates and GitHub information retrieval for spec create
|
47
|
-
#
|
48
|
-
# @todo It would be nice to have a template class that accepts options
|
49
|
-
# and uses the default ones if not provided.
|
50
|
-
# @todo The template is outdated.
|
51
|
-
|
52
|
-
def default_data_for_template(name)
|
53
|
-
data = {}
|
54
|
-
data[:name] = name
|
55
|
-
data[:version] = '0.0.1'
|
56
|
-
data[:summary] = "A short description of #{name}."
|
57
|
-
data[:homepage] = "http://EXAMPLE/#{name}"
|
58
|
-
data[:author_name] = `git config --get user.name`.strip
|
59
|
-
data[:author_email] = `git config --get user.email`.strip
|
60
|
-
data[:source_url] = "http://EXAMPLE/#{name}.git"
|
61
|
-
data[:ref_type] = ':tag'
|
62
|
-
data[:ref] = '0.0.1'
|
63
|
-
data
|
64
|
-
end
|
65
|
-
|
66
|
-
def github_data_for_template(repo_id)
|
67
|
-
repo = GitHub.repo(repo_id)
|
68
|
-
raise Informative, "Unable to fetch data for `#{repo_id}`" unless repo
|
69
|
-
user = GitHub.user(repo['owner']['login'])
|
70
|
-
raise Informative, "Unable to fetch data for `#{repo['owner']['login']}`" unless user
|
71
|
-
data = {}
|
72
|
-
|
73
|
-
data[:name] = repo['name']
|
74
|
-
data[:summary] = (repo['description'] || '').gsub(/["]/, '\"')
|
75
|
-
data[:homepage] = (repo['homepage'] && !repo['homepage'].empty?) ? repo['homepage'] : repo['html_url']
|
76
|
-
data[:author_name] = user['name'] || user['login']
|
77
|
-
data[:author_email] = user['email'] || 'email@address.com'
|
78
|
-
data[:source_url] = repo['clone_url']
|
79
|
-
|
80
|
-
data.merge suggested_ref_and_version(repo)
|
81
|
-
end
|
82
|
-
|
83
|
-
def suggested_ref_and_version(repo)
|
84
|
-
tags = GitHub.tags(repo['html_url']).map { |tag| tag['name'] }
|
85
|
-
versions_tags = {}
|
86
|
-
tags.each do |tag|
|
87
|
-
clean_tag = tag.gsub(/^v(er)? ?/, '')
|
88
|
-
versions_tags[Gem::Version.new(clean_tag)] = tag if Gem::Version.correct?(clean_tag)
|
89
|
-
end
|
90
|
-
version = versions_tags.keys.sort.last || '0.0.1'
|
91
|
-
data = { :version => version }
|
92
|
-
if version == '0.0.1'
|
93
|
-
branches = GitHub.branches(repo['html_url'])
|
94
|
-
master_name = repo['master_branch'] || 'master'
|
95
|
-
master = branches.find { |branch| branch['name'] == master_name }
|
96
|
-
raise Informative, "Unable to find any commits on the master branch for the repository `#{repo['html_url']}`" unless master
|
97
|
-
data[:ref_type] = ':commit'
|
98
|
-
data[:ref] = master['commit']['sha']
|
99
|
-
else
|
100
|
-
data[:ref_type] = ':tag'
|
101
|
-
data[:ref] = versions_tags[version]
|
102
|
-
end
|
103
|
-
data
|
104
|
-
end
|
105
|
-
|
106
|
-
def spec_template(data)
|
107
|
-
<<-SPEC
|
108
|
-
#
|
109
|
-
# Be sure to run `pod spec lint #{data[:name]}.podspec' to ensure this is a
|
110
|
-
# valid spec and to remove all comments including this before submitting the spec.
|
111
|
-
#
|
112
|
-
# To learn more about Podspec attributes see http://docs.cocoapods.org/specification.html
|
113
|
-
# To see working Podspecs in the CocoaPods repo see https://github.com/CocoaPods/Specs/
|
114
|
-
#
|
115
|
-
|
116
|
-
Pod::Spec.new do |s|
|
117
|
-
|
118
|
-
# ――― Spec Metadata ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
|
119
|
-
#
|
120
|
-
# These will help people to find your library, and whilst it
|
121
|
-
# can feel like a chore to fill in it's definitely to your advantage. The
|
122
|
-
# summary should be tweet-length, and the description more in depth.
|
123
|
-
#
|
124
|
-
|
125
|
-
s.name = "#{data[:name]}"
|
126
|
-
s.version = "#{data[:version]}"
|
127
|
-
s.summary = "#{data[:summary]}"
|
128
|
-
|
129
|
-
# This description is used to generate tags and improve search results.
|
130
|
-
# * Think: What does it do? Why did you write it? What is the focus?
|
131
|
-
# * Try to keep it short, snappy and to the point.
|
132
|
-
# * Write the description between the DESC delimiters below.
|
133
|
-
# * Finally, don't worry about the indent, CocoaPods strips it!
|
134
|
-
s.description = <<-DESC
|
135
|
-
DESC
|
136
|
-
|
137
|
-
s.homepage = "#{data[:homepage]}"
|
138
|
-
# s.screenshots = "www.example.com/screenshots_1.gif", "www.example.com/screenshots_2.gif"
|
139
|
-
|
140
|
-
|
141
|
-
# ――― Spec License ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
|
142
|
-
#
|
143
|
-
# Licensing your code is important. See http://choosealicense.com for more info.
|
144
|
-
# CocoaPods will detect a license file if there is a named LICENSE*
|
145
|
-
# Popular ones are 'MIT', 'BSD' and 'Apache License, Version 2.0'.
|
146
|
-
#
|
147
|
-
|
148
|
-
s.license = "MIT (example)"
|
149
|
-
# s.license = { :type => "MIT", :file => "FILE_LICENSE" }
|
150
|
-
|
151
|
-
|
152
|
-
# ――― Author Metadata ――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
|
153
|
-
#
|
154
|
-
# Specify the authors of the library, with email addresses. Email addresses
|
155
|
-
# of the authors are extracted from the SCM log. E.g. $ git log. CocoaPods also
|
156
|
-
# accepts just a name if you'd rather not provide an email address.
|
157
|
-
#
|
158
|
-
# Specify a social_media_url where others can refer to, for example a twitter
|
159
|
-
# profile URL.
|
160
|
-
#
|
161
|
-
|
162
|
-
s.author = { "#{data[:author_name]}" => "#{data[:author_email]}" }
|
163
|
-
# Or just: s.author = "#{data[:author_name]}"
|
164
|
-
# s.authors = { "#{data[:author_name]}" => "#{data[:author_email]}" }
|
165
|
-
# s.social_media_url = "http://twitter.com/#{data[:author_name]}"
|
166
|
-
|
167
|
-
# ――― Platform Specifics ――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
|
168
|
-
#
|
169
|
-
# If this Pod runs only on iOS or OS X, then specify the platform and
|
170
|
-
# the deployment target. You can optionally include the target after the platform.
|
171
|
-
#
|
172
|
-
|
173
|
-
# s.platform = :ios
|
174
|
-
# s.platform = :ios, "5.0"
|
175
|
-
|
176
|
-
# When using multiple platforms
|
177
|
-
# s.ios.deployment_target = "5.0"
|
178
|
-
# s.osx.deployment_target = "10.7"
|
179
|
-
# s.watchos.deployment_target = "2.0"
|
180
|
-
|
181
|
-
|
182
|
-
# ――― Source Location ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
|
183
|
-
#
|
184
|
-
# Specify the location from where the source should be retrieved.
|
185
|
-
# Supports git, hg, bzr, svn and HTTP.
|
186
|
-
#
|
187
|
-
|
188
|
-
s.source = { :git => "#{data[:source_url]}", #{data[:ref_type]} => "#{data[:ref]}" }
|
189
|
-
|
190
|
-
|
191
|
-
# ――― Source Code ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
|
192
|
-
#
|
193
|
-
# CocoaPods is smart about how it includes source code. For source files
|
194
|
-
# giving a folder will include any swift, h, m, mm, c & cpp files.
|
195
|
-
# For header files it will include any header in the folder.
|
196
|
-
# Not including the public_header_files will make all headers public.
|
197
|
-
#
|
198
|
-
|
199
|
-
s.source_files = "Classes", "Classes/**/*.{h,m}"
|
200
|
-
s.exclude_files = "Classes/Exclude"
|
201
|
-
|
202
|
-
# s.public_header_files = "Classes/**/*.h"
|
203
|
-
|
204
|
-
|
205
|
-
# ――― Resources ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
|
206
|
-
#
|
207
|
-
# A list of resources included with the Pod. These are copied into the
|
208
|
-
# target bundle with a build phase script. Anything else will be cleaned.
|
209
|
-
# You can preserve files from being cleaned, please don't preserve
|
210
|
-
# non-essential files like tests, examples and documentation.
|
211
|
-
#
|
212
|
-
|
213
|
-
# s.resource = "icon.png"
|
214
|
-
# s.resources = "Resources/*.png"
|
215
|
-
|
216
|
-
# s.preserve_paths = "FilesToSave", "MoreFilesToSave"
|
217
|
-
|
218
|
-
|
219
|
-
# ――― Project Linking ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
|
220
|
-
#
|
221
|
-
# Link your library with frameworks, or libraries. Libraries do not include
|
222
|
-
# the lib prefix of their name.
|
223
|
-
#
|
224
|
-
|
225
|
-
# s.framework = "SomeFramework"
|
226
|
-
# s.frameworks = "SomeFramework", "AnotherFramework"
|
227
|
-
|
228
|
-
# s.library = "iconv"
|
229
|
-
# s.libraries = "iconv", "xml2"
|
230
|
-
|
231
|
-
|
232
|
-
# ――― Project Settings ――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
|
233
|
-
#
|
234
|
-
# If your library depends on compiler flags you can set them in the xcconfig hash
|
235
|
-
# where they will only apply to your library. If you depend on other Podspecs
|
236
|
-
# you can include multiple dependencies to ensure it works.
|
237
|
-
|
238
|
-
# s.requires_arc = true
|
239
|
-
|
240
|
-
# s.xcconfig = { "HEADER_SEARCH_PATHS" => "$(SDKROOT)/usr/include/libxml2" }
|
241
|
-
# s.dependency "JSONKit", "~> 1.4"
|
242
|
-
|
243
|
-
end
|
244
|
-
SPEC
|
245
|
-
end
|
246
|
-
|
247
|
-
def semantic_versioning_notice(repo_id, repo)
|
248
|
-
<<-EOS
|
249
|
-
|
250
|
-
#{'――― MARKDOWN TEMPLATE ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――'.reversed}
|
251
|
-
|
252
|
-
I’ve recently added [#{repo}](https://github.com/CocoaPods/Specs/tree/master/#{repo}) to the [CocoaPods](https://github.com/CocoaPods/CocoaPods) package manager repo.
|
253
|
-
|
254
|
-
CocoaPods is a tool for managing dependencies for OSX and iOS Xcode projects and provides a central repository for iOS/OSX libraries. This makes adding libraries to a project and updating them extremely easy and it will help users to resolve dependencies of the libraries they use.
|
255
|
-
|
256
|
-
However, #{repo} doesn't have any version tags. I’ve added the current HEAD as version 0.0.1, but a version tag will make dependency resolution much easier.
|
257
|
-
|
258
|
-
[Semantic version](http://semver.org) tags (instead of plain commit hashes/revisions) allow for [resolution of cross-dependencies](https://github.com/CocoaPods/Specs/wiki/Cross-dependencies-resolution-example).
|
259
|
-
|
260
|
-
In case you didn’t know this yet; you can tag the current HEAD as, for instance, version 1.0.0, like so:
|
261
|
-
|
262
|
-
```
|
263
|
-
$ git tag -a 1.0.0 -m "Tag release 1.0.0"
|
264
|
-
$ git push --tags
|
265
|
-
```
|
266
|
-
|
267
|
-
#{'――― TEMPLATE END ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――'.reversed}
|
268
|
-
|
269
|
-
#{'[!] This repo does not appear to have semantic version tags.'.yellow}
|
270
|
-
|
271
|
-
After commiting the specification, consider opening a ticket with the template displayed above:
|
272
|
-
- link: https://github.com/#{repo_id}/issues/new
|
273
|
-
- title: Please add semantic version tags
|
274
|
-
EOS
|
275
|
-
end
|
276
|
-
end
|
277
|
-
end
|
278
|
-
end
|
279
|
-
end
|
@@ -1,94 +0,0 @@
|
|
1
|
-
module Pod
|
2
|
-
class Command
|
3
|
-
class Spec < Command
|
4
|
-
class Edit < Spec
|
5
|
-
self.summary = 'Edit a spec file.'
|
6
|
-
|
7
|
-
self.description = <<-DESC
|
8
|
-
Opens the podspec matching `QUERY` to be edited.
|
9
|
-
DESC
|
10
|
-
|
11
|
-
self.arguments = [
|
12
|
-
CLAide::Argument.new('QUERY', false),
|
13
|
-
]
|
14
|
-
|
15
|
-
def self.options
|
16
|
-
[
|
17
|
-
['--regex', 'Interpret the `QUERY` as a regular expression'],
|
18
|
-
['--show-all', 'Pick from all versions of the given podspec'],
|
19
|
-
].concat(super)
|
20
|
-
end
|
21
|
-
|
22
|
-
def initialize(argv)
|
23
|
-
@use_regex = argv.flag?('regex')
|
24
|
-
@show_all = argv.flag?('show-all')
|
25
|
-
@query = argv.shift_argument
|
26
|
-
@query = @query.gsub('.podspec', '') unless @query.nil?
|
27
|
-
super
|
28
|
-
end
|
29
|
-
|
30
|
-
def validate!
|
31
|
-
super
|
32
|
-
help! 'A podspec name is required.' unless @query
|
33
|
-
validate_regex!(@query) if @use_regex
|
34
|
-
end
|
35
|
-
|
36
|
-
def run
|
37
|
-
query = @use_regex ? @query : Regexp.escape(@query)
|
38
|
-
if @show_all
|
39
|
-
specs = get_path_of_spec(query, @show_all).split(/\n/)
|
40
|
-
message = "Which spec would you like to edit [1-#{specs.count}]? "
|
41
|
-
index = UI.choose_from_array(specs, message)
|
42
|
-
filepath = specs[index]
|
43
|
-
else
|
44
|
-
filepath = get_path_of_spec(query)
|
45
|
-
end
|
46
|
-
|
47
|
-
exec_editor(filepath.to_s) if File.exist? filepath
|
48
|
-
raise Informative, "#{ filepath } doesn't exist."
|
49
|
-
end
|
50
|
-
|
51
|
-
# Looks up an executable in the search paths
|
52
|
-
#
|
53
|
-
# @note
|
54
|
-
# Thank you homebrew
|
55
|
-
#
|
56
|
-
# @param [String] cmd
|
57
|
-
# the executable to look up
|
58
|
-
#
|
59
|
-
def which(cmd)
|
60
|
-
dir = ENV['PATH'].split(':').find { |p| File.executable? File.join(p, cmd) }
|
61
|
-
Pathname.new(File.join(dir, cmd)) unless dir.nil?
|
62
|
-
end
|
63
|
-
|
64
|
-
def which_editor
|
65
|
-
editor = ENV['EDITOR']
|
66
|
-
# If an editor wasn't set, try to pick a sane default
|
67
|
-
return editor unless editor.nil?
|
68
|
-
|
69
|
-
# Find Sublime Text 2
|
70
|
-
return 'subl' if which 'subl'
|
71
|
-
# Find Textmate
|
72
|
-
return 'mate' if which 'mate'
|
73
|
-
# Find # BBEdit / TextWrangler
|
74
|
-
return 'edit' if which 'edit'
|
75
|
-
# Default to vim
|
76
|
-
return 'vim' if which 'vim'
|
77
|
-
|
78
|
-
raise Informative, "Failed to open editor. Set your 'EDITOR' environment variable."
|
79
|
-
end
|
80
|
-
|
81
|
-
def exec_editor(*args)
|
82
|
-
return if args.to_s.empty?
|
83
|
-
safe_exec(which_editor, *args)
|
84
|
-
end
|
85
|
-
|
86
|
-
def safe_exec(cmd, *args)
|
87
|
-
# This buys us proper argument quoting and evaluation
|
88
|
-
# of environment variables in the cmd parameter.
|
89
|
-
exec('/bin/sh', '-i', '-c', cmd + ' "$@"', '--', *args)
|
90
|
-
end
|
91
|
-
end
|
92
|
-
end
|
93
|
-
end
|
94
|
-
end
|