Commit b165d71

mo khan <mo@mokhan.ca>
2014-07-25 20:15:37
pass in array to console instead of string.
1 parent 8010931
Changed files (3)
bin/tfa
@@ -1,3 +1,6 @@
 #!/usr/bin/env ruby
 
 require 'tfa'
+
+console = TFA::Console.new
+console.run(ARGV)
lib/tfa/console.rb
@@ -1,11 +1,10 @@
 module TFA
   class Console
-    def initialize(filename = "secrets")
+    def initialize(filename = "tfa")
       @storage = PStore.new(File.join(Dir.home, ".#{filename}.pstore"))
     end
 
-    def run(command)
-      arguments = command.split(' ')
+    def run(arguments)
       command_name = arguments.first
       command_for(command_name).run(arguments - [command_name])
     end
spec/lib/console_spec.rb
@@ -4,13 +4,13 @@ module TFA
     let(:secret) { ::ROTP::Base32.random_base32 }
 
     it "saves a new secret" do
-      subject.run("add development #{secret}")
-      expect(subject.run("show development")).to eql(secret)
+      subject.run(["add", "development", secret])
+      expect(subject.run(["show", "development"])).to eql(secret)
     end
 
     it "creates a totp for a certain key" do
-      subject.run("add development #{secret}")
-      expect(subject.run("totp development")).to_not be_nil
+      subject.run(["add", "development", secret])
+      expect(subject.run(["totp", "development"])).to_not be_nil
     end
   end
 end