Sha256: 7a490e3e706fdb84d92d8fc64f72deebccd235f95f84945654e325c52428f68b

Contents?: true

Size: 1.46 KB

Versions: 2

Compression:

Stored size: 1.46 KB

Contents

#!/usr/bin/env ruby

require 'lib/corto'
require 'getoptlong'
require 'ap'
require 'pp'

opts = GetoptLong.new(
  [ '--help', '-h', GetoptLong::NO_ARGUMENT ],
  [ '--version', '-v', GetoptLong::NO_ARGUMENT ], 
  [ '--purge', '-P', GetoptLong::NO_ARGUMENT ], 
  [ '--count', '-c', GetoptLong::NO_ARGUMENT],
  [ '--deflate', '-d', GetoptLong::NO_ARGUMENT]
)

shrink = true
begin 
opts.each do |opt, arg|
  case opt
    when '--help'
      ap 'usage: corto [-h|-v|-c|-P] url_to_shrink'
      exit 0
    when '--version'
      @version = File.exist?('VERSION') ? File.read('VERSION') : ""
      ap @version
      exit 0
    when '--purge'
      corto = Corto.new
      corto.purge
      ap 'corto: ' +corto.db_name+' successfully purged'
      exit 0
    when '--count'
      corto = Corto.new
      c = corto.count
      
      ap 'corto: ' + corto.db_name+' contains ' + c.to_s + ' shortened urls.'
      
      exit 0
    when '--deflate'
      shrink = false
      
  end
end
rescue 
  exit 0
end
if ARGV.length != 1
  raise 'usage: corto [-h|-v|-c|-P] url_to_shrink'
  exit 0
end

corto = Corto.new 
if (shrink)
  s = corto.shrink(ARGV[0])
  if (!s.nil?) 
    puts 'corto: ' + ARGV[0] + ' shrinked as ' + s
  else
    puts 'corto: it seems ' + ARGV[0] + ' is not a valid url to shrink'
  end
else
  s = corto.deflate(ARGV[0])
  if (!s.nil?) 
    puts 'corto: ' + ARGV[0] + ' deflated is ' + s
  else
    puts 'corto: it seems ' + ARGV[0] + ' is not a known shrinked url'
  end
end


exit 0  

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
corto-0.80.1 bin/corto
corto-0.80.0 bin/corto