class MyEpisodes::Cli
Public Class Methods
new()
click to toggle source
# File lib/my_episodes/cli.rb, line 8 def initialize @options = {action: :help} @parser = create_parser end
run(argv, io)
click to toggle source
# File lib/my_episodes/cli.rb, line 17 def self.run(argv, io) cli = self.new cli.parse(argv) cli.run(io) end
Public Instance Methods
parse(argv)
click to toggle source
# File lib/my_episodes/cli.rb, line 13 def parse(argv) @parser.parse(argv) end
run(io)
click to toggle source
# File lib/my_episodes/cli.rb, line 23 def run(io) case @options[:action] when :dump Dump.new(client, io, @options).execute when :help io.puts(@parser) end end
Private Instance Methods
client()
click to toggle source
# File lib/my_episodes/cli.rb, line 34 def client @client ||= Client.create(*@options.values_at(:username, :password)) end
create_parser()
click to toggle source
# File lib/my_episodes/cli.rb, line 38 def create_parser OptionParser.new do |opts| opts.on('-D', '--dump', 'Dump history from myepisodes.com to CSV') do @options[:action] = :dump end opts.on('-u', '--username=USERNAME', 'Username for myepisodes.com') do |username| @options[:username] = username end opts.on('-p', '--password=PASSWORD', 'Password for myepisodes.com') do |passwd| @options[:password] = passwd end opts.on('-s', '--separator=SEP', 'Separator for CSV output') do |separator| @options[:separator] = separator end opts.on('-h', '--help', 'You\'re looking at it') do @options[:action] = :help end end end