lib/tfa/console.rb in tfa-0.0.3 vs lib/tfa/console.rb in tfa-0.0.4
- old
+ new
@@ -1,27 +1,26 @@
module TFA
class Console
def initialize(filename = "tfa")
- @storage = PStore.new(File.join(Dir.home, ".#{filename}.pstore"))
+ @storage = Storage.new(filename)
end
def run(arguments)
command_name = arguments.first
command_for(command_name).run(arguments - [command_name])
end
private
def command_for(command_name)
- case command_name
- when "add"
- AddCommand.new(@storage)
- when "show"
- ShowCommand.new(@storage)
- when "totp"
- TotpCommand.new(@storage)
- else
- UsageCommand.new(@storage)
+ registry[command_name].call
+ end
+
+ def registry
+ Hash.new { |x, y| lambda { UsageCommand.new(@storage) } }.tap do |commands|
+ commands['add'] = lambda { AddCommand.new(@storage) }
+ commands['show'] = lambda { ShowCommand.new(@storage) }
+ commands['totp'] = lambda { TotpCommand.new(@storage) }
end
end
end
end