Skip to content

Verbose option #4

@FrankKair

Description

@FrankKair

As of now, the Requestor module only returns a response.body string.

It would be nice to have command line arguments such as --verbose / -v so treqs would return more information on the request such as status, headers, etc.

Here's an example of option parsing:

#!/usr/bin/env ruby
require 'optparse'
require 'treqs'

ARGV[0] = '--help' if ARGV.empty?
unless ARGV[0].include?('--') || ARGV[0].include?('-')
  puts "invalid option: #{ARGV[0]}"
end

options = {}
opt_parser = OptionParser.new do |opt|
  opt.on('--verbose', 'Shows all the request information') do |o|
    options[:verbose] = o
  end
  opt.on('--option', 'Summary of this option') do |o|
    options[:option] = o
  end
end

begin
  opt_parser.parse!
  options.keys.each do |k|
    case k
    when :verbose
      puts Treqs.call(verbose: true)
    when :option
      ...
    end
  end
rescue StandardError => e
  puts e
end

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions