Class: AppArchetype::Commands::FindTemplates

Inherits:
Object
  • Object
show all
Defined in:
lib/app_archetype/commands/find_templates.rb

Overview

Finds template by name in collection

Constant Summary collapse

RESULT_HEADER =

Output table header

%w[NAME VERSION].freeze

Instance Method Summary collapse

Constructor Details

#initialize(manager, options = Hashie::Mash.new) ⇒ FindTemplates

Returns a new instance of FindTemplates.



12
13
14
15
16
# File 'lib/app_archetype/commands/find_templates.rb', line 12

def initialize(manager, options = Hashie::Mash.new)
  @manager = manager
  @options = options
  @prompt = TTY::Prompt.new
end

Instance Method Details

#runObject

Finds a template by name from the collection

First it looks for a name option, if this is not set then the user is prompted for the template name.

Then the template manager runs a search to find a manifest with a fully or partially matching name

If there are found results they will be rendered to STDOUT in a table.

When there are no results found then a message confirming this will be printed to STDOUT.



33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/app_archetype/commands/find_templates.rb', line 33

def run
  name = @options.name
  name ||= @prompt.ask('Please enter a template name')

  manifests = @manager.search_by_name(name)

  if manifests.any?
    puts manifest_list_table(manifests).render&.strip
  else
    puts "✖ No manifests with name `#{name}` found."
  end
end