lib/aigu/cli.rb in aigu-0.1 vs lib/aigu/cli.rb in aigu-0.1.1
- old
+ new
@@ -1,15 +1,25 @@
module Aigu
class CLI
def initialize(env, argv)
@env = env
- @command = Aigu::PUBLIC_COMMANDS.include?(argv.first) ? argv.shift : nil
+ @command = argv.first =~ /[^-]/ ? argv.shift : nil
@argv = argv
parse_options
end
def run
- Aigu.send(@command, @options) if @command
+ service_name = "#{@command}er".capitalize
+
+ begin
+ service_class = Aigu.const_get(service_name)
+ rescue NameError
+ puts "The Aigu::#{service_name} service doesn’t exist. Nice try."
+ exit 0
+ end
+
+ service_object = service_class.new(@options)
+ service_object.process!
end
def parse_options
@options = {}