Class: AppArchetype::Commands::PrintTemplateVariables

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

Overview

Summarizes and prints variables from template manifest

Constant Summary collapse

VARIABLE_HEADER =

Variable table header

%w[NAME DESCRIPTION DEFAULT].freeze

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of PrintTemplateVariables.



13
14
15
16
17
# File 'lib/app_archetype/commands/print_template_variables.rb', line 13

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

Instance Method Details

#runObject

Prints manifest variables, descriptions and defaults

First it looks to the options for the manifest name. If one is not provided then the user will be prompted to choose a manifest from the list of known manifests.

If the manifest cannot be found a RuntimeError will be raised.

Once the manifest is found, an info table is rendered with the variable names, descriptions and any defined defaults.



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

def run
  name = @options.name
  name ||= @prompt.select('Please choose manifest', @manager.manifest_names)

  manifest = @manager.find_by_name(name)

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