Sha256: b3e2d3bb364988b500cc4c528d7bbae11e1b189fe9d08bc10737758e7e492094
Contents?: true
Size: 1.29 KB
Versions: 1
Compression:
Stored size: 1.29 KB
Contents
#!/usr/bin/env ruby require 'optparse' $LOAD_PATH << File.join(File.dirname(__FILE__), '..', 'lib') require 'pru' options = {} OptionParser.new do |opts| opts.banner = <<BANNER Pipeable Ruby Use ruby in your pipes, forget about grep / sed / awk / wc ... Map works on each line as String Reduce works on all lines as Array (optional or via -r) Usage: something | pru 'map' something | pru 'map' 'reduce' something | pru '' 'reduce' something | pru --reduce 'reduce' Options: BANNER opts.on("-r", "--reduce CODE","reduce via CODE") {|code| options[:reduce] = code } opts.separator '' opts.on('-I', '--libdir DIR', 'Add DIR to load path') { |dir| $LOAD_PATH << dir } opts.on('--require LIB', 'Require LIB (also comma-separated)') { |lib| begin require 'rubygems' rescue LoadError end lib.split(',').each{|l| require l } } opts.separator '' opts.on("-h", "--help","Show this.") { puts opts; exit } opts.on('-v', '--version','Show Version'){ puts Pru::VERSION; exit} end.parse! abort "Too many arguments, see --help" if ARGV.size > 2 map, reduce = ARGV reduce ||= options[:reduce] map = 'true' if not map or map.empty? if reduce results = [] Pru.map($stdin, map){|x| results << x } puts Pru.reduce(results, reduce) else Pru.map($stdin, map){|x| puts x } end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
pru-0.1.5 | bin/pru |