module AppArchetype::CLI::Presenters

CLI output presenters

Constants

RESULT_HEADER

Output table header

VALIDATION_HEADER

Validation result table header

VARIABLE_HEADER

Variable table header

Public Class Methods

manifest_list(manifests) click to toggle source

Builds a table of manifest information

@param [Array] manifests

# File lib/app_archetype/cli/presenters.rb, line 58
def manifest_list(manifests)
  table(
    header: RESULT_HEADER,
    data: manifests.map do |manifest|
      [
        manifest.name,
        manifest.version
      ]
    end
  ).show
end
table(header: [], data: [], format: 'table') click to toggle source

Creates a presenter for given data

Accepts header row data and has configurable format.

Header must be array of string

Data is array of arrays where the inner array is a row.

Format by default is a table, although can be 'csv' or 'json'.

@param header [Array] @param data [Array] @param format [String]

@return [CliFormat::Presenter]

# File lib/app_archetype/cli/presenters.rb, line 41
def table(header: [], data: [], format: 'table')
  has_header = header.any?
  opts = { header: has_header, format: format }

  presenter = CliFormat::Presenter.new(opts)
  presenter.header = header if has_header

  data.each { |row| presenter.rows << row }

  presenter
end
validation_result(results) click to toggle source

Builds a table for manifest validation results

@param [Array] results

# File lib/app_archetype/cli/presenters.rb, line 93
def validation_result(results)
  table(
    header: VALIDATION_HEADER,
    data: results.map do |result|
      [
        result
      ]
    end
  ).show
end
variable_list(variables) click to toggle source

Builds a table of variable information

@param [Array] variables

# File lib/app_archetype/cli/presenters.rb, line 75
def variable_list(variables)
  table(
    header: VARIABLE_HEADER,
    data: variables.map do |variable|
      [
        variable.name,
        variable.description,
        variable.default
      ]
    end
  ).show
end