exe/pry-try in pry-try-0.2.2 vs exe/pry-try in pry-try-0.2.3
- old
+ new
@@ -1,7 +1,46 @@
#!/usr/bin/env ruby
+if ARGV.empty? || %w(-h --help).include?(ARGV.first)
+ puts(<<-EOH)
+ EXAMPLES
+
+ Try scripts:
+
+ $ cat some-script.rb | pry-try
+
+ Try gems:
+
+ $ pry-try redis
+ ... some bundling ...
+ irb(main):001:0> Redis
+ => Redis
+
+ Multiple gems:
+
+ $ pry-try redis rake
+
+ Specific version:
+
+ $ pry-try redis '3.1.0'
+
+ ...or any requirement that would be understood by bundler:
+
+ $ pry-try redis '~> 3.1.0'
+
+ Combined with gems that don't need a specific version:
+
+ $ pry-try redis '~> 3.1.0' rake gem_with_version '1.0'
+
+EOH
+ exit
+elsif %w(-v --version).include?(ARGV.first)
+ require 'pry-try'
+ puts PryTry::VERSION
+ exit
+end
+
VERSION_LIKE_RE = [Gem::Requirement::PATTERN, /v?\d+\.\d+/, /^\h+$/].freeze
def parse_args(args)
args.each_with_object([]) do |arg, obj|
matches_arg = arg.method(:match).to_proc
@@ -17,32 +56,31 @@
'rails' => %w(rails/all active_support/all),
'activerecord' => %w(active_record),
'activesupport' => %w(active_support/all),
}.freeze
-gems = parse_args(ARGV).map do |gem|
+@gems = parse_args(ARGV).map do |gem|
if r = REQUIREMENTS[gem.first]
gem << {:require => r}
else
gem
end
end
-if $stdin.tty?
+if @gems.any?
require 'tempfile'
require 'yaml'
- script = Tempfile.new.tap do |f|
+ @script = Tempfile.new('pry-try').tap do |f|
File.write(f, <<CODEZ.gsub(/\n+ *(?=\S)/, ';'))
require 'bundler/inline'
+require 'yaml'
gemfile(true) do
source 'https://rubygems.org'
gem 'pry'
- YAML.load(#{YAML.dump(gems).inspect}).each {|gargs| gem(*gargs) }
-end
-$stdin = $stdin.reopen '/dev/tty';
+ YAML.load(#{YAML.dump(@gems).inspect}).each {|gargs| gem(*gargs) }
+end;nil
CODEZ
end
- exec %{cat #{script.path} | pry}
-else
- exec %{script=$(cat;echo; echo '$stdin = $stdin.reopen "/dev/tty";'); printf "${script}" | pry}
end
+
+ exec %{unset BUNDLE_BIN;script=$(cat #{@script ? @script.path : ''} #{$stdin.tty? ? '' : '-'}; echo;echo '$stdin = $stdin.reopen "/dev/tty";'); printf "${script}" | pry}