Sha256: 806c49417310177133225357845f24058d137d4fabedf56027dd4faf52db53b7

Contents?: true

Size: 884 Bytes

Versions: 1

Compression:

Stored size: 884 Bytes

Contents

require 'rbkb/cli'

# Copyright 2009 emonti at matasano.com 
# See README.rdoc for license information
#
# urlenc converts a string or raw data to a url percent-encoded string 
# Input can be supplied via stdin, a string argument, or a file (with -f).
# (url percent-encoding is just fancy hex encoding)
class Rbkb::Cli::Urlenc < Rbkb::Cli::Executable
  def make_parser()
    super()
    add_std_file_opt(:indat)
    arg = @oparse
    arg.banner += " <data | blank for stdin>"

    arg.on("-p", "--[no-]plus", 
           "Convert spaces to '+' (default: false)") do |p|
      @opts[:plus] = p
    end
  end

  def parse(*args)
    super(*args)
    parse_string_argument(:indat)
    parse_catchall()
  end

  def go(*args)
    super(*args)
    # Default to standard input
    @opts[:indat] ||= @stdin.read()
    @stdout << @opts[:indat].urlenc(:plus => @opts[:plus]) + "\n"
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
emonti-rbkb-0.6.2.1 lib/rbkb/cli/urlenc.rb