Sha256: 9c52fed9f6572b461a3ba4f0f08d707767faa488fac41147ff923572e6c5d7bd
Contents?: true
Size: 1.1 KB
Versions: 2
Compression:
Stored size: 1.1 KB
Contents
#!/usr/bin/env ruby require "rubygems" require "shorturl" require "optparse" include WWW class Array def pick self[rand(size)] end end def random_service ShortURL.valid_services.pick end 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 service == :random ShortURL.shorten(url, random_service) elsif 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
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
shorturl-0.8.3 | bin/shorturl |
shorturl-0.8.2 | bin/shorturl |