class RSS2Mail::CLI
Public Class Methods
defaults()
click to toggle source
Calls superclass method
# File lib/rss2mail/cli.rb, line 36 def defaults super.merge( files: nil, smtp: nil, lmtp: nil, reload: false, verbose: false, debug: false ) end
Public Instance Methods
run(arguments)
click to toggle source
# File lib/rss2mail/cli.rb, line 53 def run(arguments) if target = arguments.shift target = target.to_sym else quit 'Feeds target is required!' end quit unless arguments.empty? templates = Hash.new { |h, k| h[k] = begin File.read(File.join(TEMPLATE_PATH, "#{k}.erb")) rescue Errno::ENOENT # silently ignore end } (options.delete(:files) || default_files).each { |feeds_file| unless File.readable?(feeds_file) warn "Feeds file not found: #{feeds_file}" next end feeds = Util.load_feeds(feeds_file) unless target_feeds = feeds.get(target) warn "Feeds target not found in #{feeds_file}: #{target}" next end target_feeds.each { |feed| Feed.new(feed, options).deliver(templates) unless feed[:skip] } Util.dump_feeds(feeds, target, target_feeds) unless options[:debug] } end
usage()
click to toggle source
# File lib/rss2mail/cli.rb, line 49 def usage "#{super} <target>" end
Private Instance Methods
default_files()
click to toggle source
# File lib/rss2mail/cli.rb, line 117 def default_files File.directory?(dir = DEFAULT_FEEDS_PATH) ? Dir[File.join(dir, '*.yaml')] : [DEFAULT_FEEDS_FILE] end
opts(opts)
click to toggle source
# File lib/rss2mail/cli.rb, line 93 def opts(opts) opts.option(:directory__DIRECTORY, 'Process all feeds in directory') { |dir| quit "#{dir}: No such file or directory" unless File.directory?(dir) quit "#{dir}: Permission denied" unless File.readable?(dir) options[:files] = Dir[File.join(dir, '*.yaml')] } opts.separator %w[smtp lmtp].each { |type| klass = Transport.const_get(type.upcase) opts.on("-#{type[0, 1]}", "--#{type} [HOST[:PORT]]", "Send mail through #{type.upcase} server", "[Default host: #{klass::DEFAULT_HOST}, default port: #{klass::DEFAULT_PORT}]") { |host| options[type.to_sym] = host.to_s } } opts.separator opts.switch(:reload, 'Reload feeds') end