Commit 0c2cd999 authored by Samuel E. Giddins's avatar Samuel E. Giddins

Merge pull request #4531 from hemal/master

Adding pod env command to print environment
parents 0f3eb52b b01b71dd
......@@ -8,6 +8,10 @@ To install release candidates run `[sudo] gem install cocoapods --pre`
##### Enhancements
* Added support for `pod env` to print the pod environment without having to crash.
[Hemal Shah](https://github.com/hemal)
[#3660](https://github.com/CocoaPods/CocoaPods/issues/3660)
* Add support for specifying :source with a pod dependency.
[Eric Firestone](https://github.com/efirestone)
[#4486](https://github.com/CocoaPods/CocoaPods/pull/4486)
......
......@@ -24,6 +24,7 @@ module Pod
require 'cocoapods/command/spec'
require 'cocoapods/command/init'
require 'cocoapods/command/cache'
require 'cocoapods/command/env'
self.abstract_command = true
self.command = 'pod'
......
require 'cocoapods/user_interface/error_report'
module Pod
class Command
class Env < Command
self.summary = 'Display pod environment'
self.description = 'Display pod environment.'
def self.options
options = []
options.concat(super.reject { |option, _| option == '--silent' })
end
def initialize(argv)
super
config.silent = false
end
def run
UI.puts report
end
def report
<<-EOS
#{stack}
#{executable_path}
### Plugins
```
#{plugins_string}
```
#{markdown_podfile}
EOS
end
def stack
UI::ErrorReport.stack
end
def markdown_podfile
UI::ErrorReport.markdown_podfile
end
def plugins_string
UI::ErrorReport.plugins_string
end
private
def executable_path
<<-EOS
### Installation Source
```
Executable Path: #{actual_path}
```
EOS
end
def actual_path
$PROGRAM_NAME
end
end
end
end
require File.expand_path('../../spec_helper', __FILE__)
module Pod
describe Command::Env do
describe 'In general' do
before do
@report = Command::Env
end
it 'returns a well-structured environment report' do
expected = <<-EOS
### Stack
```
CocoaPods : #{Pod::VERSION}
Ruby : #{RUBY_DESCRIPTION}
RubyGems : #{Gem::VERSION}
Host : :host_information
Xcode : :xcode_information
Git : :git_information
Ruby lib dir : #{RbConfig::CONFIG['libdir']}
Repositories : repo_1
repo_2
```
### Installation Source
```
Executable Path: /usr/bin/command
```
### Plugins
```
cocoapods : #{Pod::VERSION}
cocoapods-core : #{Pod::VERSION}
cocoapods-plugins : 1.2.3
```
### Podfile
```ruby
```
EOS
@report.stubs(:actual_path).returns('/usr/bin/command')
report.should == expected
end
end
end
end
......@@ -18,28 +18,9 @@ module Pod
#{original_command}
```
### Report
* What did you do?
* What did you expect to happen?
* What happened instead?
### Stack
```
CocoaPods : #{Pod::VERSION}
Ruby : #{RUBY_DESCRIPTION}
RubyGems : #{Gem::VERSION}
Host : #{host_information}
Xcode : #{xcode_information}
Git : #{git_information}
Ruby lib dir : #{RbConfig::CONFIG['libdir']}
Repositories : #{repo_information.join("\n ")}
```
#{report_instructions}
#{stack}
### Plugins
```
......@@ -71,16 +52,41 @@ Don't forget to anonymize any private data!
EOS
end
private
def report_instructions
<<-EOS
### Report
def `(other)
super
rescue Errno::ENOENT => e
"Unable to find an executable (#{e})"
* What did you do?
* What did you expect to happen?
* What happened instead?
EOS
end
def pathless_exception_message(message)
message.gsub(/- \(.*\):/, '-')
def stack
<<-EOS
### Stack
```
CocoaPods : #{Pod::VERSION}
Ruby : #{RUBY_DESCRIPTION}
RubyGems : #{Gem::VERSION}
Host : #{host_information}
Xcode : #{xcode_information}
Git : #{git_information}
Ruby lib dir : #{RbConfig::CONFIG['libdir']}
Repositories : #{repo_information.join("\n ")}
```
EOS
end
def plugins_string
plugins = installed_plugins
max_name_length = plugins.keys.map(&:length).max
plugins.map do |name, version|
"#{name.ljust(max_name_length)} : #{version}"
end.sort.join("\n")
end
def markdown_podfile
......@@ -95,6 +101,18 @@ EOS
EOS
end
private
def `(other)
super
rescue Errno::ENOENT => e
"Unable to find an executable (#{e})"
end
def pathless_exception_message(message)
message.gsub(/- \(.*\):/, '-')
end
def error_from_podfile(error)
if error.message =~ /Podfile:(\d*)/
"\nIt appears to have originated from your Podfile at line #{Regexp.last_match[1]}.\n"
......@@ -130,14 +148,6 @@ EOS
reduce({}) { |hash, s| hash.tap { |h| h[s.name] = s.version.to_s } }
end
def plugins_string
plugins = installed_plugins
max_name_length = plugins.keys.map(&:length).max
plugins.map do |name, version|
"#{name.ljust(max_name_length)} : #{version}"
end.sort.join("\n")
end
def repo_information
SourcesManager.all.map do |source|
next unless source.type == 'file system'
......
......@@ -16,6 +16,7 @@ module Pod
Command.parse(%w(spec create )).should.be.instance_of Command::Spec::Create
Command.parse(%w(spec lint )).should.be.instance_of Command::Spec::Lint
Command.parse(%w(init )).should.be.instance_of Command::Init
Command.parse(%w(env )).should.be.instance_of Command::Env
end
end
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment