lib/rbkb/cli/hexify.rb in emonti-rbkb-0.6.2.1 vs lib/rbkb/cli/hexify.rb in emonti-rbkb-0.6.6
- old
+ new
@@ -13,11 +13,11 @@
# Add local options
arg.banner += " <data | blank for stdin>"
arg.on("-l", "--length LEN", Numeric, "Output lines of LEN bytes") do |l|
- bail("Length must be greater than zero") unless (@opts[:len] = l) > 0
+ @opts[:len] = l
end
arg.on("-d", "--delim=DELIMITER", "DELIMITER between each byte") do |d|
@opts[:delim] = d
end
@@ -49,12 +49,12 @@
# Default to standard input
@opts[:indat] ||= @stdin.read()
indat = @opts.delete(:indat)
- len = @opts.delete(:len)
+ len = (@opts.delete(:len) || indat.length)
- self.exit(1) unless((len ||= indat.length) > 0)
+ bail("Length must be greater than zero") unless(len > 0)
until (m = indat.slice!(0..len-1)).empty?
@stdout << m.hexify(@opts)
@stdout.puts((opts[:delim] and ! indat.empty?)? opts[:delim] : "\n")
end