Class: Fetcher::Runner
- Inherits:
-
Object
- Object
- Fetcher::Runner
- Includes:
- LogUtils::Logging
- Defined in:
- lib/fetcher/cli/runner.rb
Instance Attribute Summary collapse
-
#opts ⇒ Object
readonly
Returns the value of attribute opts.
Instance Method Summary collapse
-
#initialize ⇒ Runner
constructor
A new instance of Runner.
- #run(args) ⇒ Object
Constructor Details
#initialize ⇒ Runner
Returns a new instance of Runner.
21 22 23 |
# File 'lib/fetcher/cli/runner.rb', line 21 def initialize @opts = Opts.new end |
Instance Attribute Details
#opts ⇒ Object (readonly)
Returns the value of attribute opts.
19 20 21 |
# File 'lib/fetcher/cli/runner.rb', line 19 def opts @opts end |
Instance Method Details
#run(args) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 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 |
# File 'lib/fetcher/cli/runner.rb', line 25 def run( args ) opt=OptionParser.new do |cmd| cmd. = "Usage: fetch [options] URI" cmd.on( '-o', '--output PATH', "Output Path (default is '#{opts.output_path}')" ) { |s| opts.output_path = s } # todo: find different letter for debug trace switch (use v for version?) cmd.on( '-v', '--verbose', 'Show debug trace' ) do LogUtils::Logger.root.level = :debug end usage =" \nfetch \#{VERSION} - Lets you fetch text documents or binary blobs via HTTP, HTTPS.\n\n\#{cmd.help}\n\nExamples:\n fetch https://raw.github.com/openfootball/at-austria/master/2013_14/bl.txt\n fetch -o downloads https://raw.github.com/openfootball/at-austria/master/2013_14/bl.txt\n\nFurther information:\n https://github.com/geraldb/fetcher\n\n" ## todo: also add -? if possible as alternative cmd.on_tail( '-h', '--help', 'Show this message' ) do puts usage exit end end opt.parse!( args ) puts Fetcher. args.each do |arg| src = arg uri = URI.parse( src ) logger.debug "uri.host=<#{uri.host}>, uri.path=<#{uri.path}>" if uri.path == '/' || uri.path == '' dest = "#{opts.output_path}/#{uri.host}" else dest = "#{opts.output_path}/#{uri.host}@#{uri.path.gsub( /[ \-]/, '_').gsub( /[\/\\]/, '-')}" end Worker.new.copy( src, dest ) end # each arg puts 'Done.' end |