module Sinew::Args

Public Class Methods

slop(args) click to toggle source
# File lib/sinew/args.rb, line 14
def self.slop(args)
  slop = Slop.parse(args) do |o|
    o.banner = 'Usage: sinew [options] [recipe.sinew]'
    o.integer '-l', '--limit', 'quit after emitting this many rows'
    o.string '--proxy', 'use host[:port] as HTTP proxy (can be a comma-delimited list)'
    o.integer '--timeout', 'maximum time allowed for the transfer'
    o.bool '-s', '--silent', 'suppress some output'
    o.bool '-v', '--verbose', 'dump emitted rows while running'

    o.separator 'From httpdisk:'
    o.string '--dir', 'set custom cache directory'
    # note: uses slop_duration from HTTPDisk
    o.duration '--expires', 'when to expire cached requests (ex: 1h, 2d, 3w)'
    o.bool '--force', "don't read anything from cache (but still write)"
    o.bool '--force-errors', "don't read errors from cache (but still write)"

    # generic
    o.boolean '--version', 'show version' do
      puts "sinew #{Sinew::VERSION}"
      exit
    end
    o.on('--help', 'show this help') do
      puts o
      exit
    end
  end

  # recipe argument
  recipe = slop.args.first
  raise Slop::Error, '' if args.empty?
  raise Slop::Error, 'no RECIPE specified' if !recipe
  raise Slop::Error, 'more than one RECIPE specified' if slop.args.length > 1
  raise Slop::Error, "#{recipe} not found" if !File.exist?(recipe)

  slop.to_h.tap do
    _1[:recipe] = recipe
  end
end