Class: Digestif::CLI
- Inherits:
-
Object
- Object
- Digestif::CLI
- Defined in:
- lib/digestif/cli.rb
Instance Attribute Summary collapse
-
#args ⇒ Object
Returns the value of attribute args.
-
#options ⇒ Object
Returns the value of attribute options.
Class Method Summary collapse
Instance Method Summary collapse
- #error(error_obj_or_str, code = 1) ⇒ Object
-
#initialize(args) ⇒ CLI
constructor
A new instance of CLI.
- #parse_options ⇒ Object
- #run ⇒ Object
Constructor Details
#initialize(args) ⇒ CLI
Returns a new instance of CLI.
22 23 24 25 |
# File 'lib/digestif/cli.rb', line 22 def initialize(args) self.args = args self. = end |
Instance Attribute Details
#args ⇒ Object
Returns the value of attribute args.
20 21 22 |
# File 'lib/digestif/cli.rb', line 20 def args @args end |
#options ⇒ Object
Returns the value of attribute options.
20 21 22 |
# File 'lib/digestif/cli.rb', line 20 def @options end |
Class Method Details
.default_options ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/digestif/cli.rb', line 12 def self. = OpenStruct.new .digest = :sha1 .seek_size = 1024 .read_size = 512 end |
.run(args) ⇒ Object
8 9 10 |
# File 'lib/digestif/cli.rb', line 8 def self.run(args) new(args).run end |
Instance Method Details
#error(error_obj_or_str, code = 1) ⇒ Object
97 98 99 100 101 102 103 104 105 106 |
# File 'lib/digestif/cli.rb', line 97 def error(error_obj_or_str, code = 1) if error_obj_or_str.respond_to?('to_s') error_str = error_obj_or_str.to_s else error_str = error_obj_or_str.inspect end $stderr.puts "digestif: #{error_str}" exit code end |
#parse_options ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/digestif/cli.rb', line 41 def = CLI. parser = OptionParser.new do |p| p. = "Usage: digestif [options] filename" p.separator "" p.separator "Options:" p.separator "" p.on("-d", "--digest DIGEST", [:md5, :sha1], "Digest algorithm to use. Currently supported:", " md5", " sha1", "(default #{.digest.to_s})", ' ') do |digest| .digest = digest end p.on("--print-sample-count", "outputs the number of samples used to create the hash") do .print_sample_count = true end p.on("-r", "--read-size SIZE", Integer, "Size of chunk to read, in bytes " + "(#{.read_size})") do |size| .read_size = size end p.on("-s", "--seek-size SIZE", Integer, "Size of chunk to skip after each read, in bytes " + "(#{.seek_size})") do |size| .seek_size = size end p.on_tail("-v", "--version", "Show version") do puts Digestif.version_string exit 0 end p.on_tail("-h", "--help", "This is it") do puts p exit 0 end end begin parser.parse!(args) rescue OptionParser::ParseError => e error e end end |