class RSS2Mail::CLI

Public Class Methods

defaults() click to toggle source
Calls superclass method
   # File lib/rss2mail/cli.rb
36 def defaults
37   super.merge(
38     files:   nil,
39     smtp:    nil,
40     lmtp:    nil,
41     reload:  false,
42     verbose: false,
43     debug:   false
44   )
45 end

Public Instance Methods

run(arguments) click to toggle source
   # File lib/rss2mail/cli.rb
53 def run(arguments)
54   if target = arguments.shift
55     target = target.to_sym
56   else
57     quit 'Feeds target is required!'
58   end
59 
60   quit unless arguments.empty?
61 
62   templates = Hash.new { |h, k|
63     h[k] = begin
64       File.read(File.join(TEMPLATE_PATH, "#{k}.erb"))
65     rescue Errno::ENOENT
66       # silently ignore
67     end
68   }
69 
70   (options.delete(:files) || default_files).each { |feeds_file|
71     unless File.readable?(feeds_file)
72       warn "Feeds file not found: #{feeds_file}"
73       next
74     end
75 
76     feeds = Util.load_feeds(feeds_file)
77 
78     unless target_feeds = feeds.get(target)
79       warn "Feeds target not found in #{feeds_file}: #{target}"
80       next
81     end
82 
83     target_feeds.each { |feed|
84       Feed.new(feed, options).deliver(templates) unless feed[:skip]
85     }
86 
87     Util.dump_feeds(feeds, target, target_feeds) unless options[:debug]
88   }
89 end
usage() click to toggle source
   # File lib/rss2mail/cli.rb
49 def usage
50   "#{super} <target>"
51 end

Private Instance Methods

default_files() click to toggle source
    # File lib/rss2mail/cli.rb
117 def default_files
118   File.directory?(dir = DEFAULT_FEEDS_PATH) ?
119     Dir[File.join(dir, '*.yaml')] : [DEFAULT_FEEDS_FILE]
120 end
opts(opts) click to toggle source
    # File lib/rss2mail/cli.rb
 93 def opts(opts)
 94   opts.option(:directory__DIRECTORY, 'Process all feeds in directory') { |dir|
 95     quit "#{dir}: No such file or directory" unless File.directory?(dir)
 96     quit "#{dir}: Permission denied"         unless File.readable?(dir)
 97 
 98     options[:files] = Dir[File.join(dir, '*.yaml')]
 99   }
100 
101   opts.separator
102 
103   %w[smtp lmtp].each { |type|
104     klass = Transport.const_get(type.upcase)
105 
106     opts.on("-#{type[0, 1]}", "--#{type} [HOST[:PORT]]", "Send mail through #{type.upcase} server",
107             "[Default host: #{klass::DEFAULT_HOST}, default port: #{klass::DEFAULT_PORT}]") { |host|
108       options[type.to_sym] = host.to_s
109     }
110   }
111 
112   opts.separator
113 
114   opts.switch(:reload, 'Reload feeds')
115 end