Sha256: 3d66a3c39a7b927563c9caf9f840ea91180974dac62d592abf478ee1305335be

Contents?: true

Size: 1.61 KB

Versions: 7

Compression:

Stored size: 1.61 KB

Contents

#!/usr/bin/env ruby

require 'optparse'
require 'terminal-table'
require 'magento_remote'

# Sweet, sweet options.
options = {}

optparse = OptionParser.new do |opts|
  opts.banner = "Usage: magento_find_product [OPTIONS]\n  Find product(s) in shop."

  opts.separator ""
  opts.separator "Magento shop options"

  opts.on('-b', '--base-uri URI', 'base URI of shop.') do |b|
    options[:base_uri] = b
  end

  opts.separator ""
  opts.separator "Product options"

  # TODO Make this an argument.
  opts.on('-s', '--search-term SEARCHTERM', 'term to search for (sku, name, description...)') do |s|
    options[:search_term] = s
  end

  opts.separator ""
  opts.separator "Output options"

  opts.on('-d', '--debug FILE', 'enable debugging output, STDOUT, or FILE if given') do |d|
    if d
      options[:debug] = d
    else
      options[:debug] = true
    end
  end

  opts.separator ""
  opts.separator "General options"

  opts.on_tail('--version', 'Show version.') do
    puts "magento_find_product #{MagentoRemote::VERSION}"
    exit 0
  end
  opts.on('-h', '--help', 'Show help.') do
    puts opts
    exit 0
  end
end

optparse.parse!

if !options[:base_uri] || !options[:search_term]
  STDERR.puts "Error: You have to define search_term and base_uri"
  exit 1
end

mech = MagentoMech.from_config options
if options[:debug] == true
  mech.log_to! STDOUT
elsif options[:debug]
  mech.log_to! options[:debug]
end

return_code = 0

matches = mech.find_product options[:search_term]
if matches.nil?
  puts "Nothing found"
else
  puts Terminal::Table.new :headings => ['Name', 'Product ID', 'In stock?'], :rows => matches
end

exit return_code

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
magento_remote-0.1.6 bin/magento_find_product
magento_remote-0.1.5 bin/magento_find_product
magento_remote-0.1.4 bin/magento_find_product
magento_remote-0.1.3 bin/magento_find_product
magento_remote-0.1.2 bin/magento_find_product
magento_remote-0.1.1 bin/magento_find_product
magento_remote-0.1.0 bin/magento_find_product