Class: AppArchetype::Commands::DeleteTemplate
- Inherits:
-
Object
- Object
- AppArchetype::Commands::DeleteTemplate
- Defined in:
- lib/app_archetype/commands/delete_template.rb
Overview
Deletes template from collection
Instance Method Summary collapse
-
#initialize(manager, options = Hashie::Mash.new) ⇒ DeleteTemplate
constructor
A new instance of DeleteTemplate.
-
#run ⇒ Object
Deletes a manifest from template dir.
Constructor Details
#initialize(manager, options = Hashie::Mash.new) ⇒ DeleteTemplate
Returns a new instance of DeleteTemplate.
7 8 9 10 11 |
# File 'lib/app_archetype/commands/delete_template.rb', line 7 def initialize(manager, = Hashie::Mash.new) @manager = manager @options = @prompt = TTY::Prompt.new end |
Instance Method Details
#run ⇒ Object
Deletes a manifest from template dir
First it looks in options for the name of the manifest to delete. If this is not set then the user is presented a list of manifests to choose from.
When the manifest specified does not exist a runtime error will be raised
The user will then be prompted with a yes/no prompt to confirm they wish to delete the selected manifest.
If the answer to this is no, the command will stop
Otherwise, the template and manifest will be removed from the template dir
A success message will be presented to confirm to the user that the operation was successful.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/app_archetype/commands/delete_template.rb', line 34 def run name = @options.name name ||= @prompt.select( 'Please choose template for deletion', @manager.manifest_names ) manifest = @manager.find_by_name(name) unless manifest puts "✖ No template with name `#{name}` found." return end ok_to_proceed = @prompt.yes?("Are you sure you want to delete #{name}?") return unless ok_to_proceed FileUtils.rm_rf(manifest.parent_path) puts("✔ Template `#{name}` has been removed") end |