Class: Rbkb::Cli::B64

Inherits:
Executable show all
Defined in:
lib/rbkb/cli/b64.rb

Overview

Copyright 2009 emonti at matasano.com See README.rdoc for license information

b64 converts strings or raw data to base-64 encoding.

Instance Attribute Summary

Attributes inherited from Executable

#argv, #exit_status, #oparse, #opts, #stderr, #stdin, #stdout

Instance Method Summary collapse

Methods inherited from Executable

#bail, #bail_args, #exit, #initialize, run

Constructor Details

This class inherits a constructor from Rbkb::Cli::Executable

Instance Method Details

#go(*args) ⇒ Object



29
30
31
32
33
# File 'lib/rbkb/cli/b64.rb', line 29

def go(*args)
  super(*args)
  @stdout << @opts[:indat].b64(opts[:len]).chomp + "\n"
  self.exit(0)
end

#make_parserObject



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/rbkb/cli/b64.rb', line 8

def make_parser
  super()
  arg = @oparse
  arg.banner += " <data | blank for stdin>"

  add_std_file_opt(:indat)

  arg.on("-l", "--length LEN", Numeric, "Output LEN chars per line") do |l|
      bail("length must be > 0") unless l > 0
      @opts[:len] = l
  end
end

#parse(*args) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/rbkb/cli/b64.rb', line 21

def parse(*args)
  super(*args)
  parse_string_argument(:indat)
  parse_file_argument(:indat)
  parse_catchall()
  @opts[:indat] ||= @stdin.read
end