Sha256: 060d3e897b1c11efb827f2a7d9d59f6f71c1376f07c130ce9992e5aa04a33525

Contents?: true

Size: 918 Bytes

Versions: 11

Compression:

Stored size: 918 Bytes

Contents

require 'rbkb/cli'

# Copyright 2009 emonti at matasano.com 
# See README.rdoc for license information
#
# Returns a slice from input. This is just a shell interface to a String.slice 
# operation.
class Rbkb::Cli::Slice < Rbkb::Cli::Executable

  def initialize(*args)
    super(*args)
    @opts[:last] ||= -1
  end

  def make_parser()
    super()
    add_std_file_opt(:indat)
    add_range_opts(:first, :last)
    arg = @oparse

    arg.banner += " start (no args when using -r or -x)"
  end


  def parse(*args)
    super(*args)
    @opts[:first] ||= @argv.shift

    unless(Numeric === @opts[:first] or /^-?\d+$/.match(@opts[:first]) )
      bail_args "invalid start length"
    end

    parse_catchall()

    @opts[:first] = @opts[:first].to_i
    @opts[:indat] ||= @stdin.read()
  end


  def go(*args)
    super(*args)
    @stdout << @opts[:indat][ @opts[:first] .. @opts[:last] ]
    self.exit(0)
  end

end

Version data entries

11 entries across 11 versions & 2 rubygems

Version Path
emonti-rbkb-0.6.6 lib/rbkb/cli/slice.rb
emonti-rbkb-0.6.7 lib/rbkb/cli/slice.rb
emonti-rbkb-0.6.8 lib/rbkb/cli/slice.rb
emonti-rbkb-0.6.9.1 lib/rbkb/cli/slice.rb
emonti-rbkb-0.6.9 lib/rbkb/cli/slice.rb
rbkb-0.7.2 lib/rbkb/cli/slice.rb
rbkb-0.7.1 lib/rbkb/cli/slice.rb
rbkb-0.7.0 lib/rbkb/cli/slice.rb
rbkb-0.6.12 lib/rbkb/cli/slice.rb
rbkb-0.6.11 lib/rbkb/cli/slice.rb
rbkb-0.6.10 lib/rbkb/cli/slice.rb