lib/link_shrink/cli.rb in link_shrink-0.0.2 vs lib/link_shrink/cli.rb in link_shrink-0.0.3
- old
+ new
@@ -11,27 +11,38 @@
end
# Configures the arguments for the command
# @param opts [OptionParser]
def set_options(opts)
+ %w(@json @qr_code @tiny_url)
@json = false
@qr_code = false
+ @tiny_url = false
+ @google = false
opts.version = LinkShrink::VERSION
opts.banner = <<MSG
Usage: link_shrink [OPTION] [URL]
Description:
LinkShrink, Turn long and nasty links into short urls.
Options:
MSG
opts.set_program_name 'LinkShrink'
+ opts.on_head('-t', '--tinyurl', 'use TinyURL') do
+ @tiny_url = :true
+ end
+
+ opts.on_head('-g', '--google', 'use Google (Default)') do
+ @google = :true
+ end
+
opts.on_head('-j', '--json', 'return JSON response') do
@json = :true
end
opts.on_head('-q', '--qrcode', 'return QR Code') do
- @qr_code = :true
+ @qr_code = :true unless @tiny_url
end
opts.on_tail('-v', '--version', 'display the version of LinkShrink and exit') do
puts opts.version
exit
@@ -51,13 +62,14 @@
return process_url if url_present?
opts.help
end
def process_url
+ LinkShrink.configure { |c| c.api = 'TinyUrl' } if @tiny_url
LinkShrink.shrink_url(@args.last, { json: @json, qr_code: @qr_code })
end
def url_present?
- !!(@args.last =~ /^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$/)
+ !!(@args.last =~ /^(http?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$/)
end
end
-end
\ No newline at end of file
+end