Class: Appydave::Tools::Jump::Commands::Remove
- Defined in:
- lib/appydave/tools/jump/commands/remove.rb
Overview
Remove command deletes a location entry
Instance Attribute Summary collapse
-
#force ⇒ Object
readonly
Returns the value of attribute force.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
Attributes inherited from Base
#config, #options, #path_validator
Instance Method Summary collapse
-
#initialize(config, key, force: false, path_validator: PathValidator.new, **options) ⇒ Remove
constructor
A new instance of Remove.
- #run ⇒ Object
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, **) super(config, path_validator: path_validator, **) @key = key @force = force end |
Instance Attribute Details
#force ⇒ Object (readonly)
Returns the value of attribute force.
9 10 11 |
# File 'lib/appydave/tools/jump/commands/remove.rb', line 9 def force @force end |
#key ⇒ Object (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
#run ⇒ Object
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., code: 'NOT_FOUND') end |