Sha256: 29195b01b0c92993727041dd98a89f3d739bbb36aa367b89430a06c22825aba1

Contents?: true

Size: 901 Bytes

Versions: 11

Compression:

Stored size: 901 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"
    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/urlenc.rb
emonti-rbkb-0.6.7 lib/rbkb/cli/urlenc.rb
emonti-rbkb-0.6.8 lib/rbkb/cli/urlenc.rb
emonti-rbkb-0.6.9.1 lib/rbkb/cli/urlenc.rb
emonti-rbkb-0.6.9 lib/rbkb/cli/urlenc.rb
rbkb-0.7.2 lib/rbkb/cli/urlenc.rb
rbkb-0.7.1 lib/rbkb/cli/urlenc.rb
rbkb-0.7.0 lib/rbkb/cli/urlenc.rb
rbkb-0.6.12 lib/rbkb/cli/urlenc.rb
rbkb-0.6.11 lib/rbkb/cli/urlenc.rb
rbkb-0.6.10 lib/rbkb/cli/urlenc.rb