Class: Rly::Commands::Add

Inherits:
Rly::Command show all
Defined in:
lib/rly/commands/add.rb

Instance Method Summary collapse

Methods inherited from Rly::Command

#command, #cursor, #editor, #exec_exist?, #generator, #pager, #platform, #prompt, #screen, #which

Constructor Details

#initialize(name, url, options) ⇒ Add

Returns a new instance of Add.



9
10
11
12
13
# File 'lib/rly/commands/add.rb', line 9

def initialize(name, url, options)
  @name = name
  @url = url
  @options = options
end

Instance Method Details

#execute(input: $stdin, output: $stdout) ⇒ Object



15
16
17
18
19
20
21
22
23
# File 'lib/rly/commands/add.rb', line 15

def execute(input: $stdin, output: $stdout)
  shortcuts = Rly::Shortcuts.new
  if !shortcuts.exist?(@name) || @options[:force]
    shortcuts.create(@name, @url)
    output.puts "rly #{@name} in this directory will now open #{@url}"
  else
    output.puts "that name is used already. if you want to overwrite, use -f"
  end
end