Class: Epodder::Arguments
- Inherits:
-
Object
- Object
- Epodder::Arguments
- Defined in:
- lib/arguments.rb
Instance Attribute Summary collapse
-
#args ⇒ Object
Returns the value of attribute args.
Instance Method Summary collapse
- #get_args ⇒ Object
-
#initialize ⇒ Arguments
constructor
A new instance of Arguments.
- #method_missing(name, value = nil, *args) ⇒ Object
Constructor Details
#initialize ⇒ Arguments
Returns a new instance of Arguments.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/arguments.rb', line 5 def initialize @args = Hash.new @args[:arguments] = [] verb = Struct.new(:name,:desc,:block) @verbs = [ verb.new('add','Add a new podcast.', Proc.new {|args| @args[:action] = :add; @args[:arguments] = args}), verb.new('catchup','Mark older episodes as downloaded.', Proc.new {|args| @args[:action] = :catchup; @args[:arguments] = args}), verb.new('remove','Remove a feed by supplying an id.', Proc.new {|args| @args[:action] = :remove; @args[:arguments] = args}), verb.new('lscasts','List podcasts.', Proc.new {|args| @args[:action] = :list_podcast; @args[:arguments] = args}), verb.new('lseps','List episodes of a podcast by id.', Proc.new {|args| @args[:action] = :list_episodes; @args[:arguments] = args}), verb.new('fetch','Update then download podcasts', Proc.new {|args| @args[:action] = :fetch; @args[:arguments] = args}), verb.new('download','Download podcasts specified by a list of id or all podcasts', Proc.new {|args| @args[:action] = :download; @args[:arguments] = args}), verb.new('update','Update podcasts specified by a list of id or all podcasts', Proc.new {|args| @args[:action] = :update; @args[:arguments] = args}), verb.new("clean", "Remove old content from the database", Proc.new {|args| @args[:action] = :clean; @args[:arguments] = args}) ] get_args end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, value = nil, *args) ⇒ Object
48 49 50 51 52 |
# File 'lib/arguments.rb', line 48 def method_missing(name, value=nil, *args) if @args.has_key? name @args[name] end end |
Instance Attribute Details
#args ⇒ Object
Returns the value of attribute args.
3 4 5 |
# File 'lib/arguments.rb', line 3 def args @args end |
Instance Method Details
#get_args ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/arguments.rb', line 23 def get_args @args[:path] = "~/.epodder" cmd = CmdParse::CommandParser.new( true, true ) cmd.program_name = "ePodder" cmd.program_version = [0, 0, 7] cmd. = CmdParse::OptionParserWrapper.new do |opt| opt.separator "Global options:" opt.on("-v", "--verbose", "Be verbose when outputting info") {|t| @args[:verbose] = true } opt.on("-c", "--conf-dir [PATH]", "Set the configuration directory") {|path| @args[:path] = path} opt.on("-l", "--log-path [PATH]", "Set logging to the specified file") {|path| @args[:log_file] = path} end cmd.add_command( CmdParse::HelpCommand.new ) cmd.add_command( CmdParse::VersionCommand.new) @verbs.each do |verb| command = CmdParse::Command.new(verb.name, false, false) command.short_desc = verb.desc command.set_execution_block(&verb.block) cmd.add_command(command) end cmd.parse end |