Permalink
Browse files

command line tool

  • Loading branch information...
1 parent 9f0b59f commit 548bd1d078d1635b354435278daf36bc428f7aa9 @dml dml committed Dec 22, 2011
Showing with 68 additions and 3 deletions.
  1. +9 −2 README.md
  2. +4 −1 bin/tokenifier
  3. +55 −0 lib/tokenifier/cli.rb
View
11 README.md
@@ -41,9 +41,16 @@ Using custom secret
## CLI usage
-To generate client token
+Usage:
- tokenifier string "some-identy-string" [--secret=OPTIONAL_SECRET_STRING]
+ tokinifier [options] COMMAND 'custom string'
+Commands
+ tokinifier e|encrypt "CUSTOM DATA"
+ tokinifier d|decrypt "CUSTOM DATA"
+Using custom secret
+
+ tokinifier --secret CUSTOMSECRET e|encrypt "CUSTOM DATA"
+ tokinifier --secret CUSTOMSECRET d|decrypt "ENCRYPTED DATA"
View
5 bin/tokenifier
@@ -1,4 +1,7 @@
#!/usr/bin/env ruby
+require 'rubygems'
require 'tokinifier'
-Tokinifier::CLI.run
+require 'tokinifier/cli'
+
+Tokenifier::Cli.run
View
55 lib/tokenifier/cli.rb
@@ -0,0 +1,55 @@
+require 'optparse'
+
+module Tokenifier
+ module Cli
+ extend self
+
+ def options
+ @options ||= {}
+ end
+
+ def optparse
+ OptionParser.new do |opts|
+ opts.banner =<<-USAGE
+Usage: tokinifier [options] COMMAND 'custom string'
+
+ tokinifier e|encrypt "CUSTOM DATA"
+ tokinifier d|decrypt "CUSTOM DATA"
+
+ tokinifier --secret CUSTOMSECRET e|encrypt "CUSTOM DATA"
+ tokinifier --secret CUSTOMSECRET d|decrypt "ENCRYPTED DATA"
+
+USAGE
+
+ opts.on('-s', '--secret SECRET', 'Using custom secret phrase') do |secret|
+ options[:secret] = secret
+ end
+
+ opts.on('-h', '--help', 'Display this screen') do
+ puts opts
+ exit
+ end
+ end
+ end
+
+ def run
+ unless ARGV.size == 2
+ optparse.help
+ exit
+ end
+
+ optparse.parse!
+
+ puts case ARGV.first
+ when /^e/
+ Tokenifier.encrypt(ARGV.last, options)
+ when /^d/
+ Tokenifier.decrypt(ARGV.last, options)
+ else
+ optparse.help
+ exit
+ end
+ end
+
+ end
+end

0 comments on commit 548bd1d

Please sign in to comment.