Sha256: 0c6d3feeba6c8fd88d1d92e19b73dde75bb02abf94b2121775e8b967d912e381

Contents?: true

Size: 928 Bytes

Versions: 1

Compression:

Stored size: 928 Bytes

Contents

#!/usr/bin/env ruby

require "rubygems"
require "shorturl"
require "optparse"

include WWW

def service_list
  ShortURL.valid_services.map { |s| s.to_s }.sort.join("\n\t")
end

def main
  service = :rubyurl
  op = OptionParser.new do |opts|
    opts.banner = "Usage: #{File.basename($0)} [<options>] <url>"
    opts.on("-h", "--help", "Displays help") { puts opts; exit }
    opts.on("-s", "--service <service>", String,
            "Uses <service> instead of RubyURL
Available services:\n\t" + service_list) { |s| service = s.to_sym }
    opts.parse!
  end

  if ARGV.empty?
    puts op
    exit(-1)
  end
  
  url = ARGV.shift
  shorturl = if ShortURL.valid_services.include?(service)
               ShortURL.shorten(url, service)
             else
               puts "Invalid service"
               exit(-1)
             end

  puts shorturl || "Unable to get shortened URL.  Maybe the URL is already too short?"
end

main

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
shorturl-0.8.1 bin/shorturl