Class: Kuzya::Commands::Open

Inherits:
Base
  • Object
show all
Defined in:
lib/kuzya/commands/open.rb

Constant Summary collapse

URL_REGEXP =
/\A#{URI::regexp(['http', 'https'])}\z/.freeze

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

args_without_command, call

Constructor Details

#initialize(url) ⇒ Open

Returns a new instance of Open.



24
25
26
# File 'lib/kuzya/commands/open.rb', line 24

def initialize(url)
  @url = url
end

Class Method Details

.infoObject



9
10
11
12
13
14
15
16
17
# File 'lib/kuzya/commands/open.rb', line 9

def info
  <<-INFO
#{'open'.bold} - to open any link run '#{'kuzya www.example.com'.italic}'
Also you can use your saved shortcuts instead of writing entire URL
e.g. add 'gh' shortcut as 'https://github.com' and 'rb' as 'ruby'
with 'kuzya add' command and run '#{'kuzya gh rb rake'.italic}'. Kuzya will make
the URL and open 'https://github.com/ruby/rake'.
  INFO
end

.prepare(args, config) ⇒ Object



19
20
21
# File 'lib/kuzya/commands/open.rb', line 19

def prepare(args, config)
  [Kuzya::UrlBuilder.call(args, config)]
end

Instance Method Details

#callObject



28
29
30
31
32
33
34
35
# File 'lib/kuzya/commands/open.rb', line 28

def call
  puts "Open #{url}"
  raise unless url =~ URL_REGEXP

  Launchy.open(url)
rescue
  puts "Can't open '#{url}', please check it, maybe you don't have shortcuts or URL is invalid".red
end