Module: Sinew::Args

Defined in:
lib/sinew/args.rb

Class Method Summary collapse

Class Method Details

.slop(args) ⇒ Object

Raises:

  • (Slop::Error)


14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# 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