Module: HTTPDisk::Cli::Args
- Defined in:
- lib/httpdisk/cli/args.rb
Overview
Slop parsing. This is broken out so we can run without require ‘httpdisk’.
Class Method Summary collapse
Class Method Details
.slop(args) ⇒ Object
11 12 13 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 52 53 54 |
# File 'lib/httpdisk/cli/args.rb', line 11 def self.slop(args) slop = Slop.parse(args) do |o| o. = "httpdisk [options] [url]" # similar to curl o.separator "Similar to curl:" o.string "-d", "--data", "HTTP POST data" o.array "-H", "--header", "pass custom header(s) to server", delimiter: nil o.boolean "-i", "--include", "include response headers in the output" o.integer "-m", "--max-time", "maximum time allowed for the transfer" o.string "-o", "--output", "write to file instead of stdout" o.string "-x", "--proxy", "use host[:port] as proxy" o.string "-X", "--request", "HTTP method to use" o.integer "--retry", "retry request if problems occur" o.boolean "-s", "--silent", "silent mode (don't print errors)" o.string "-A", "--user-agent", "send User-Agent to server" # from httpdisk o.separator "Specific to httpdisk:" o.string "--dir", "httpdisk cache directory (defaults to ~/httpdisk)" o.duration "--expires", "when to expire cached requests (ex: 1h, 2d, 3w)" o.boolean "--force", "don't read anything from cache (but still write)" o.boolean "--force-errors", "don't read errors from cache (but still write)" o.boolean "--status", "show status for a url in the cache" # generic o.boolean "--version", "show version" do puts "httpdisk #{HTTPDisk::VERSION}" exit end o.on "--help", "show this help" do puts o exit end end raise Slop::Error, "" if args.empty? raise Slop::Error, "no URL specified" if slop.args.empty? raise Slop::Error, "more than one URL specified" if slop.args.length > 1 slop.to_h.tap do _1[:url] = slop.args.first end end |