bin/dropcaster in dropcaster-0.0.2 vs bin/dropcaster in dropcaster-0.0.3

- old
+ new

@@ -1,111 +1,117 @@ -#!/usr/bin/env ruby - -$:.unshift File.join(File.dirname(__FILE__), *%w[.. lib]) - -require 'rubygems' -require 'yaml' - -help = <<HELP -Dropcaster is a podcast feed generator for the command line. - -Author: Nicolas E. Rabenau nerab@gmx.at -Homepage: http://nerab.github.com/dropcaster/ - -Basic Usage: - - dropcaster Prints a podcast feed document for the mp3 files in the current directory. - dropcaster [FILE]... Prints a podcast feed document for FILES - dropcaster [DIR]... Prints a podcast feed document for the mp3 files in DIR - -Options: - -HELP - -def usage - "Run '#{File.basename(__FILE__)} --help' for further help." -end - -require 'optparse' -require 'dropcaster' - -options = Hash.new -options[:verbose] = false -options[:auto_detect_channel_file] = true - -opts = OptionParser.new do |opts| - opts.banner = help - - opts.on("--verbose", "Verbose mode - displays additional diagnostic information") do |file| - options[:verbose] = true - end - - opts.on("--channel FILE", "Read the channel definition from FILE instead of channel.yml in the current directory.") do |file| - begin - STDERR.puts "Reading channel definition from #{file}" if options[:verbose] - options = YAML.load_file(file).merge(options) - options[:auto_detect_channel_file] = false - rescue - STDERR.puts "Error loading channel definition: #{$!.message}" - STDERR.puts $!.backtrace if options[:verbose] - exit(1) - end - end - - opts.on("--title STRING", "Use STRING as the channel's title. Overrides settings read from channel definition file.") do |title| - STDERR.puts "Setting channel title to '#{title}' via command line" if options[:verbose] - options[:title] = title - end - - opts.on("--url URL", "Use URL as the channel's url. Overrides settings read from channel definition file.") do |url| - STDERR.puts "Setting channel URL to '#{url}' via command line" if options[:verbose] - options[:url] = url - end - - opts.on("--description STRING", "Use STRING as the channel's description. Overrides settings read from channel definition file.") do |description| - STDERR.puts "Setting channel description to '#{description}' via command line" if options[:verbose] - options[:description] = description - end - - opts.on("--enclosure_base URL", "Use URL as base URL for the channel's enclosures. Overrides settings read from channel definition file.") do |enclosure_base| - STDERR.puts "Setting enclosure base to '#{enclosure_base}' via command line" if options[:verbose] - options[:enclosure_base] = enclosure_base - end - - opts.on("--channel-template FILE", "Use FILE as template for generating the channel feed. Overrides the default that comes with Dropcaster.") do |file| - options[:template] = file - end - - opts.on("--version", "Display current version") do - puts "#{File.basename(__FILE__)} " + Dropcaster::VERSION - exit 0 - end -end - -opts.parse! -sources = ARGV.blank? ? '.' : ARGV - -if options[:auto_detect_channel_file] - # There was no channel file specified, so we try to load channel.yml from sources dir - channel_file = Dropcaster::ChannelFileLocator.locate(sources) - - if File.exists?(channel_file) - STDERR.puts "Auto-detected channel file at #{channel_file}" if options[:verbose] - options_from_yaml = YAML.load_file(channel_file) - options = options_from_yaml.merge(options) - else - STDERR.puts "No #{channel_file} found." - STDERR.puts usage - exit(1) # No way to continue without a channel definition - end -end - -STDERR.puts "Generating the channel with these options: #{options.inspect}" if options[:verbose] - -begin - puts Dropcaster::Channel.new(sources, options).to_rss -rescue - STDERR.puts "Error generating the channel feed: #{$!.message}" - STDERR.puts usage - STDERR.puts $!.backtrace if options[:verbose] - exit(1) -end +#!/usr/bin/env ruby + +$:.unshift File.join(File.dirname(__FILE__), *%w[.. lib]) + +require 'rubygems' +require 'yaml' + +help = <<HELP +Dropcaster is a podcast feed generator for the command line. + +Author: Nicolas E. Rabenau nerab@gmx.at +Homepage: http://nerab.github.com/dropcaster/ + +Basic Usage: + + dropcaster Prints a podcast feed document for the mp3 files in the current directory. + dropcaster [FILE]... Prints a podcast feed document for FILES + dropcaster [DIR]... Prints a podcast feed document for the mp3 files in DIR + +Options: + +HELP + +def usage + "Run '#{File.basename(__FILE__)} --help' for further help." +end + +require 'optparse' +require 'dropcaster' + +options = Hash.new +options[:verbose] = false +options[:auto_detect_channel_file] = true + +opts = OptionParser.new do |opts| + opts.banner = help + + opts.on("--verbose", "Verbose mode - displays additional diagnostic information") do |file| + options[:verbose] = true + end + + opts.on("--channel FILE", "Read the channel definition from FILE instead of channel.yml in the current directory.") do |file| + begin + STDERR.puts "Reading channel definition from #{file}" if options[:verbose] + options = YAML.load_file(file).merge(options) + options[:auto_detect_channel_file] = false + rescue + STDERR.puts "Error loading channel definition: #{$!.message}" + STDERR.puts $!.backtrace if options[:verbose] + exit(1) + end + end + + opts.on("--title STRING", "Use STRING as the channel's title. Overrides settings read from channel definition file.") do |title| + STDERR.puts "Setting channel title to '#{title}' via command line" if options[:verbose] + options[:title] = title + end + + opts.on("--url URL", "Use URL as the channel's url. Overrides settings read from channel definition file.") do |url| + STDERR.puts "Setting channel URL to '#{url}' via command line" if options[:verbose] + options[:url] = url + end + + opts.on("--description STRING", "Use STRING as the channel's description. Overrides settings read from channel definition file.") do |description| + STDERR.puts "Setting channel description to '#{description}' via command line" if options[:verbose] + options[:description] = description + end + + opts.on("--enclosures URL", "Use URL as the base URL for the channel's enclosures. Overrides settings read from channel definition file.") do |enclosures_url| + STDERR.puts "Setting enclosures base URL to '#{enclosures_url}' via command line" if options[:verbose] + options[:enclosures_url] = enclosures_url + end + + opts.on("--image URL", "Use URL as the channel's image URL. Overrides settings read from channel definition file.") do |image_url| + STDERR.puts "Setting image URL to '#{image_url}' via command line" if options[:verbose] + options[:image_url] = image_url + end + + opts.on("--channel-template FILE", "Use FILE as template for generating the channel feed. Overrides the default that comes with Dropcaster.") do |file| + STDERR.puts "Using'#{file}' as channel template file" if options[:verbose] + options[:channel_template] = file + end + + opts.on("--version", "Display current version") do + puts "#{File.basename(__FILE__)} " + Dropcaster::VERSION + exit 0 + end +end + +opts.parse! +sources = ARGV.blank? ? '.' : ARGV + +if options[:auto_detect_channel_file] + # There was no channel file specified, so we try to load channel.yml from sources dir + channel_file = Dropcaster::ChannelFileLocator.locate(sources) + + if File.exists?(channel_file) + STDERR.puts "Auto-detected channel file at #{channel_file}" if options[:verbose] + options_from_yaml = YAML.load_file(channel_file) + options = options_from_yaml.merge(options) + else + STDERR.puts "No #{channel_file} found." + STDERR.puts usage + exit(1) # No way to continue without a channel definition + end +end + +STDERR.puts "Generating the channel with these options: #{options.inspect}" if options[:verbose] + +begin + puts Dropcaster::Channel.new(sources, options).to_rss +rescue + STDERR.puts $!.message + STDERR.puts usage + STDERR.puts $!.backtrace if options[:verbose] + exit(1) +end