Sha256: 52b9bd3e4f7f0162072dd1e046fbb36359af1150863d0bb96a70884b8b856ac1

Contents?: true

Size: 961 Bytes

Versions: 3

Compression:

Stored size: 961 Bytes

Contents

# Author Eric Monti (emonti at matasano)
require 'optparse'

module RBkB
  module CommandLine
    # exits with a message on stderr
    def bail(msg)
      STDERR.puts msg if msg
      exit 1
    end

    # returns a OptionsParser object with blackbag standard options
    def bkb_stdargs(o=OptionParser.new, cfg=OPTS)
      o=OptionParser.new 
      o.banner = "Usage: #{File.basename $0} [options]"

      o.on("-h", "--help", "Show this message") do
        bail(o)
      end

      o.on("-v", "--version", "Show version and exit") do
        bail("Ruby BlackBag version #{RBkB::VERSION}")
      end
    end

    # returns a OptionsParser object with blackbag input options
    def bkb_inputargs(o=OptionParser.new, cfg=OPTS)
      o.on("-f", "--file FILENAME", 
      "Input from FILENAME") do |f|
        begin
          cfg[:indat] = File.read(f) 
        rescue 
          bail "File Error: #{$!}"
        end
      end

      return o
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
emonti-rbkb-0.6.1.1 lib/rbkb/command_line.rb
emonti-rbkb-0.6.1.2 lib/rbkb/command_line.rb
emonti-rbkb-0.6.1.3 lib/rbkb/command_line.rb