Sha256: bc78cc25289466372d17fe4e7f37e865ae9c2f5e5156c22b2977603bfc7f1e2b

Contents?: true

Size: 1.02 KB

Versions: 4

Compression:

Stored size: 1.02 KB

Contents

#!/usr/bin/env ruby
# frozen_string_literal: true

require 'fd'
require 'optparse'
require 'ostruct'

arguments = OpenStruct.new
arguments.width = 10

options = OptionParser.new do |opts|
  opts.banner = "Usage: #{File.basename __FILE__} [options] [file_names]"

  opts.on('-w', '--width=WIDTH [Integer]', Integer, 'Display upto _width_ bytes per row, optional, default is 10') do |width|
    arguments.width = width
  end

  opts.on('-h', '--help', 'Display using this help') do
    puts opts
    puts '', 'When no file names a given fd reads from STDIN.'
    exit
  end

  opts.on('-v', '--version', 'Display version info and quit') do
    puts "fd version: #{Fd.version}"
    exit
  end
end

begin
  ARGV.push('-h') if ARGV.empty? && ARGF.eof?
  options.parse!
rescue OptionParser::InvalidArgument
  puts "fd doesn't work, this way:"
  options.parse %w[--help]
  exit 1
end

file_dumper = Fd.new(arguments.width)

if ARGV.size.positive?
  ARGV.each do |fn|
    file_dumper.dump_file(fn)
  end
else
  file_dumper.dump_stdin(STDIN.read)
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
fd-1.0.0 bin/fd
fd-0.6.0 bin/fd
fd-0.5.0 bin/fd
fd-0.4.0 bin/fd