Method: Topicz::Application#initialize

Defined in:
lib/topicz/application.rb

#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