Class: Topicz::Application

Inherits:
Object
  • Object
show all
Defined in:
lib/topicz/application.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(arguments = ARGV, factory = CommandFactory.new) ⇒ Application

Returns a new instance of Application.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/topicz/application.rb', line 12

def initialize(arguments = ARGV, factory = CommandFactory.new)
  config_file = nil
  OptionParser.new do |options|
    options.banner = 'Usage: topicz [options] <command> [options]'
    options.program_name = 'topicz'
    options.version = Topicz::VERSION
    options.on('-c', '--config FILE', 'Uses FILE as the configuration file') do |file|
      config_file = file
    end
    options.separator ''
    options.separator 'Where <command> is one of: '
    options.separator ''
    options.separator Topicz::COMMANDS.to_s
  end.order! arguments

  unless arguments.empty?
    command = arguments.shift
    if Topicz::COMMANDS.has_key? command
      @command = factory.create_command(command, config_file, arguments)
    end
  end
end

Instance Attribute Details

#commandObject (readonly)

Returns the value of attribute command.



10
11
12
# File 'lib/topicz/application.rb', line 10

def command
  @command
end

Instance Method Details

#runObject



35
36
37
38
39
40
41
# File 'lib/topicz/application.rb', line 35

def run
  if @command != nil
    @command.execute
  else
    raise 'Invalid command. Try topicz --help'
  end
end