Created
April 25, 2010 18:00
-
-
Save tekwiz/378579 to your computer and use it in GitHub Desktop.
Opens a gem and its direct dependencies in text mate
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# Opens the source code for a gem and the gem's direct dependencies in textmate. | |
# | |
# When this is mature it will be added to [Dionysus](http://github.com/tekwiz/dionysus). | |
# | |
# TODO add banner and better docs to option parser | |
# TODO add --quiet flag to suppress dependency not found warnings | |
# TODO add recursive dependencies (e.g. failure: `mate-gem rails 3.0.0.beta3` does not load activemodel | |
# since that is a dependency of activerecord) | |
# * should this have a flag to activate or suppress? | |
# * do we need to use bundler's dependency resolver? | |
# TODO add multiple gem loading (e.g. `mate-gem rails inherited_resources dionysus`) | |
# * thoughts on version definition syntax/flagging? | |
# (e.g. `mate-gem rails-3.0.0.beta3 rspec-core-2.0.0.beta.7`) | |
# * is a dot allowed in a gem name? i.e. is this parsable: | |
# `mate-gem rails 3.0.0.beta3 rspec-core-2.0.0.beta.7` | |
# TODO can this be abstracted for vim, emacs, or any other editor? | |
EDITOR = 'mate' | |
require 'optparse' | |
require 'ostruct' | |
require 'rubygems' | |
require 'highline/import' | |
$options = OpenStruct.new | |
$options.dependencies = :immediate | |
$options.gem_name = nil | |
$options.gem_version = nil | |
$options.simple = false | |
opts = OptionParser.new do |opts| | |
opts.on('-d', '--dependencies DEPTH', [:immediate, :deep], "Download a new backup copy") do |v| | |
$options.dependencies = v | |
end | |
opts.on('-s', '--simple', "Run the simple interface. Basically, no color.") do | |
$options.simple = true | |
end | |
opts.on_tail("-h", "--help", "Show this message") do | |
puts opts | |
exit | |
end | |
end | |
opts.parse!(ARGV) | |
$options.gem_name = ARGV.shift | |
$options.gem_version = ARGV.shift | |
unless ARGV.empty? | |
say(%(Invalid arguments.)) | |
puts opts | |
exit(1) | |
end | |
if $options.gem_version | |
gem_specs = [Gem.source_index.find_name($options.gem_name, $options.gem_version).first] | |
else | |
t_ = Gem.source_index.find_name($options.gem_name) | |
gem_specs = [t_.sort_by {|spec| spec.version}.last] | |
end | |
gem_specs.compact! | |
if gem_specs.nil? or gem_specs.empty? | |
say(%(<%=color("ERROR Gem not found", BOLD, RED) %> #{$options.gem_name} (#{$options.gem_version}))) | |
exit(1) | |
end | |
gem_specs.first.dependencies.each do |dep| | |
if (t_ = Gem.source_index.find_name(dep.name, dep.requirement)).empty? | |
say(%(<%=color("WARNING Dependency Not Found", BOLD) %> #{dep.to_s})) | |
else | |
gem_specs << t_.sort_by {|spec| spec.version}.last | |
end | |
end | |
puts '' | |
exec EDITOR + " " + gem_specs.collect! {|s| s.full_gem_path}.join(' ') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment