From 1f19610af5f5a28443b996f79df122a9ba6d7c0e Mon Sep 17 00:00:00 2001 From: Breno Moura Date: Tue, 13 May 2014 17:26:23 -0300 Subject: [PATCH] =?UTF-8?q?Altera=20op=C3=A7=C3=B5es=20do=20menu?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/postmon | 79 +++++++++++++++++++++++++++++++++-------------------- 1 file changed, 49 insertions(+), 30 deletions(-) diff --git a/bin/postmon b/bin/postmon index 510e359..bc4e502 100755 --- a/bin/postmon +++ b/bin/postmon @@ -2,37 +2,56 @@ # encoding: utf-8 require 'postmon_cli' +require 'optparse' -readme = <<-HELP - Usage: postmon [value] - - Commands: - cep Consultar CEP - ex: postmon cep 49015040 - - cidade Consultar informações de uma cidade - ex: postmon cidade SE Aracaju - - estado Consultar informações de um estado - ex: postmon estado SE - - rastreio Consultar informações de rastreio de um pacote - ex: postmon rastreio AA987654321BR -HELP - -unless ARGV.empty? - case ARGV.first - when "cep" - PostmonCli::Wrapper.cep(ARGV.last) - when "cidade" - PostmonCli::Wrapper.cidade(ARGV[1], ARGV[2]) - when "estado" - PostmonCli::Wrapper.estado(ARGV.last) - when "rastreio" - PostmonCli::Wrapper.rastreio(ARGV.last) - else - puts "Opção inválida" +options = {} + +opt_parser = OptionParser.new do |opt| + opt.banner = "Usage postmon [options] [value]" + opt.separator "" + opt.separator " Commands" + opt.separator " cep Consultar CEP" + opt.separator " ex: postmon cep 49015040" + opt.separator "" + opt.separator " cidade Consultar informações de uma cidade" + opt.separator " ex: postmon cidade SE Aracaju" + opt.separator "" + opt.separator " estado Consultar informações de um estado" + opt.separator " ex: postmon estado SE" + opt.separator "" + opt.separator " rastreio Consultar informações de rastreio de um pacote" + opt.separator " ex: postmon rastreio AA987654321BR" + opt.separator "" + opt.separator " Options" + + opt.on("-s", "--save", "Salva o resultado para consultas posteriores") do |save| + options[:save] = save + end + + opt.on("-f", "--first", "Pesquisa pelo primeiro") do |first| + options[:first] = first + end + + opt.on("-l", "--last", "Pesquisa pelo útimo") do |last| + options[:last] = last end + + opt.on("-c", "--clear", "Remove todo o histórico") do |clear| + options[:clear] = clear + end +end + +opt_parser.parse! + +case ARGV.first +when "cep" + PostmonCli::Wrapper.cep(ARGV.last) +when "cidade" + PostmonCli::Wrapper.cidade(ARGV[1], ARGV[2]) +when "estado" + PostmonCli::Wrapper.estado(ARGV.last) +when "rastreio" + PostmonCli::Wrapper.rastreio(ARGV.last) else - puts readme + puts opt_parser end