Class: Win32::CaptureIE::CLI::PrtIE
- Inherits:
-
Object
- Object
- Win32::CaptureIE::CLI::PrtIE
- Defined in:
- lib/win32/capture_ie/cli/prt_ie.rb
Overview
:nodoc:
Constant Summary collapse
- DEFAULT_ARGUMENTS =
%W(--output-digest=MD5)
Class Method Summary collapse
Instance Method Summary collapse
- #arguable(arr_or_arguable) ⇒ Object
- #option_parser(opt) ⇒ Object
- #parse_options(args) ⇒ Object
- #perform(args) ⇒ Object
- #usage_and_exit(exit_code, message, parser, out = $stdout) ⇒ Object
Class Method Details
.start(args) ⇒ Object
12 13 14 |
# File 'lib/win32/capture_ie/cli/prt_ie.rb', line 12 def self.start(args) self.new.perform(args) end |
Instance Method Details
#arguable(arr_or_arguable) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/win32/capture_ie/cli/prt_ie.rb', line 17 def arguable(arr_or_arguable) case arr_or_arguable when OptionParser::Arguable arr_or_arguable when Array arr_or_arguable.dup.extend(OptionParser::Arguable) else raise ArgumentError, "Invalid option `#{arr_or_arguable.inspect}:#{arr_or_arguable.class}'" + " (expected Array or OptionParser::Arguable)" end end |
#option_parser(opt) ⇒ Object
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 |
# File 'lib/win32/capture_ie/cli/prt_ie.rb', line 46 def option_parser(opt) Proc.new do |parser| parser.program_name = "prtie" parser.version = Win32::CaptureIE::VERSION::STRING parser. = "Usage: #{parser.program_name} [options] URL" parser.separator "" parser.on("-w", "--wait=SECONDS", Float, "wait SECONDS between retrievals") {|v| opt.wait = v } parser.on("-d", "--output-directory=DIRECTORY", "save capture to DIRECTORY/...") {|v| opt.outdir = v } parser.on("-o", "--output=FILE", "save capture to FILE") {|v| opt.output = v } parser.on("-T", "--output-type=TYPE", "save capture as image TYPE", "Default: PNG (RMagick available)", " or BMP (not available)") {|v| opt.output_type = v } parser.on("-D", "--output-digest=ALGORITHM", "use output filename as hex-encoded version", "of a given URL", "ALGORITHM: MD5, SHA1, SHA512 ...") {|v| opt.output_digest = v } parser.separator "" parser.on("-v", "--version", "print the version"){ puts parser.ver exit 0 } parser.on("-h", "--help", "print this message"){ puts parser exit 0 } parser.separator "" parser.separator " Default options:" parser.separator " #{DEFAULT_ARGUMENTS * ' '}" parser end end |
#parse_options(args) ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/win32/capture_ie/cli/prt_ie.rb', line 91 def (args) opt = Win32::CaptureIE::Commands::PrtIE::Option.new proc = option_parser(opt) arguable(DEFAULT_ARGUMENTS).(&proc).parse! parser = args.(&proc) begin parser.parse! rescue OptionParser::ParseError => e usage_and_exit(2, e., parser) end opt.url = ARGV.shift [opt, parser] end |
#perform(args) ⇒ Object
36 37 38 39 40 41 42 43 44 |
# File 'lib/win32/capture_ie/cli/prt_ie.rb', line 36 def perform(args) opt, parser = (arguable(args)) act = Win32::CaptureIE::Commands::PrtIE::Action.new begin act.perform(opt) rescue ArgumentError => e usage_and_exit(2, e., parser) end end |
#usage_and_exit(exit_code, message, parser, out = $stdout) ⇒ Object
29 30 31 32 33 34 |
# File 'lib/win32/capture_ie/cli/prt_ie.rb', line 29 def usage_and_exit(exit_code, , parser, out=$stdout) m = .sub(/\.?\z/, ".") out.puts "Error: #{m}" out.puts parser exit(2) end |