Class: Appydave::Tools::Jump::Commands::Remove

Inherits:
Base
  • Object
show all
Defined in:
lib/appydave/tools/jump/commands/remove.rb

Overview

Remove command deletes a location entry

Instance Attribute Summary collapse

Attributes inherited from Base

#config, #options, #path_validator

Instance Method Summary collapse

Constructor Details

#initialize(config, key, force: false, path_validator: PathValidator.new, **options) ⇒ Remove

Returns a new instance of Remove.



11
12
13
14
15
# File 'lib/appydave/tools/jump/commands/remove.rb', line 11

def initialize(config, key, force: false, path_validator: PathValidator.new, **options)
  super(config, path_validator: path_validator, **options)
  @key = key
  @force = force
end

Instance Attribute Details

#forceObject (readonly)

Returns the value of attribute force.



9
10
11
# File 'lib/appydave/tools/jump/commands/remove.rb', line 9

def force
  @force
end

#keyObject (readonly)

Returns the value of attribute key.



9
10
11
# File 'lib/appydave/tools/jump/commands/remove.rb', line 9

def key
  @key
end

Instance Method Details

#runObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/appydave/tools/jump/commands/remove.rb', line 17

def run
  # Validate key exists
  location = config.find(key)
  unless location
    suggestions = find_suggestions(key)
    suggestion = suggestions.empty? ? nil : "Did you mean: #{suggestions.join(', ')}?"
    return error_result("Location '#{key}' not found", code: 'NOT_FOUND', suggestion: suggestion)
  end

  # Require --force
  unless force
    return error_result(
      "Use --force to confirm removal of '#{key}'",
      code: 'CONFIRMATION_REQUIRED'
    )
  end

  # Remove
  config.remove(key)
  config.save

  success_result(
    message: "Location '#{key}' removed successfully",
    removed: location.to_h
  )
rescue ArgumentError => e
  error_result(e.message, code: 'NOT_FOUND')
end