Skip to content

Commit

Permalink
Allow a CLI user to pass a password switch.
Browse files Browse the repository at this point in the history
  • Loading branch information
Manfred committed Oct 16, 2012
1 parent 7e26340 commit 1031459
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
11 changes: 9 additions & 2 deletions lib/oja/cli.rb
Expand Up @@ -8,21 +8,28 @@ def initialize(argv)
end

def usage
puts "Usage: #{File.basename($0)} <receipt-file>"
puts "Usage: #{File.basename($0)} <receipt-file> [options]"
puts ""
puts "Options"
puts " -p, --password <password>"
end

def receipt_filename
@argv[0]
end

def password
@options['p'] || @options['password']
end

def print_receipt_details(receipt_data)
receipt_data.each do |key, value|
puts "#{key}: #{value}"
end
end

def check_receipt
if response = Oja.verify_filename(receipt_filename)
if response = Oja.verify_filename(:filename => receipt_filename, :password => password)
if response.active?
puts "[!] Receipt appears to be valid and active"
puts
Expand Down
5 changes: 5 additions & 0 deletions spec/cli_spec.rb
Expand Up @@ -17,6 +17,11 @@
output.should.include 'product_id'
end

it "allows you to pass a password" do
cli = Oja::CLI.new([receipt_filename('receipt'), '--password', 'secret'])
cli.password.should == 'secret'
end

it "shows a message when the receipt is invalid" do
Oja::Mock.responses << [200, { status: Oja::Response.status_code(:inactive) }]
output = oja(receipt_filename('receipt'))
Expand Down

0 comments on commit 1031459

Please sign in to comment.