Skip to content

Instantly share code, notes, and snippets.

@alexvollmer
Created August 8, 2009 17:50
Show Gist options
  • Save alexvollmer/164466 to your computer and use it in GitHub Desktop.
Save alexvollmer/164466 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require "rubygems"
require "rubygems/command_manager"
cm = Gem::CommandManager.instance
commands = cm.instance_variable_get(:@commands).keys.map { |c| cm[c.to_s] }
commands.sort_by{ |c| c.command }.each do |command|
options = command.instance_variable_get(:@option_groups)
args = options[:options].map do |opts|
flags, other = opts.first.partition { |x| x =~ /^-/ }
long, short = flags.partition { |x| x =~ /^--/ }.map { |x| x.first }
description = other.select { |x| String === x }.join(' ')
long = case long
when / /
long.split(' ').first
when /\[.*\]/
long.gsub(/[\[\]]/, '')
else
long
end
if long and short
%Q< "(#{short} #{long})"{#{short},#{long}}"[#{description}]" \\>
elsif long
%Q< "*#{long}[#{description}]" \\>
else
%Q< "*#{short}[#{description}]" \\>
end
end.sort.join("\n")
puts "_gem_#{command.command}() {"
puts " _arguments \\"
case command.usage
when /FILE/
puts " *:file:_files -f \\"
when /GEMNAME/
puts ' ":gemname:__all_gems" \\'
end
puts args unless args.empty?
puts " $gem_general_flags && ret=0"
puts "}"
puts
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment