Class: Rubyists::Opr::Commands::Rm

Inherits:
Rubyists::Opr::Command show all
Defined in:
lib/rubyists::opr/commands/rm.rb

Overview

the rm command

Instance Attribute Summary

Attributes inherited from Rubyists::Opr::Command

#options

Instance Method Summary collapse

Methods inherited from Rubyists::Opr::Command

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

Constructor Details

#initialize(item, options) ⇒ Rm

Returns a new instance of Rm.



11
12
13
14
# File 'lib/rubyists::opr/commands/rm.rb', line 11

def initialize(item, options)
  @item = item
  @options = options
end

Instance Method Details

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

rubocop:disable Lint/UnusedMethodArgument



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/rubyists::opr/commands/rm.rb', line 16

def execute(input: $stdin, output: $stdout) # rubocop:disable Lint/UnusedMethodArgument
  vault_name = if options[:vault]
                 options[:vault]
               else
                 warn 'No vault given, using "Private"'
                 'Private'
               end
  Opr. do
    found = Item.find(@item, vault: vault_name)
    return(output.puts("No item '#{@item}' found in vault '#{vault_name}'")) if found.nil?

    found.delete!
    output.puts "Removed '#{@item}' from '#{vault_name}'"
  end
end