Created
December 27, 2008 23:32
-
-
Save ursm/40331 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| out = `rake --help` | |
| sss = out.lines.map(&:strip).grep(/^-/).map {|s| | |
| opt = /(?:-¥w|--[-¥w]+?)/ | |
| arg = /¥[?([A-Z]+)¥]?/ | |
| s.match(/(#{opt}(?:, #{opt})*)(?: #{arg})? {2,}(.*)/).to_a[1..-1] | |
| }.reject(&:nil?) | |
| hs = sss.map {|opts, arg, desc| | |
| opts.split(/, /).inject(:short => [], :long => []) {|h, opt| | |
| case opt | |
| when /^--([-¥w]+)$/ | |
| h.tap {|i| i[:long] << $1 } | |
| when /^-(¥w)$/ | |
| h.tap {|i| i[:short] << $1 } | |
| else | |
| raise opt | |
| end | |
| }.merge(:arg => arg, :desc => desc) | |
| } | |
| puts hs.map {|h| | |
| short = h[:short].map {|s| "-s #{s}" } | |
| long = h[:long].map {|s| "-l #{s}" } | |
| desc = (d = h[:desc]) ? "-d #{d.inspect}" : '' | |
| ['complete -c rake', short, long, desc].reject(&:empty?).join(' ') | |
| }.join("¥n") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment