Module: AppArchetype::CLI::Presenters
- Defined in:
- lib/app_archetype/cli/presenters.rb
Overview
CLI output presenters
Constant Summary collapse
- RESULT_HEADER =
Output table header
%w[NAME VERSION].freeze
- VARIABLE_HEADER =
Variable table header
%w[NAME DESCRIPTION DEFAULT].freeze
- VALIDATION_HEADER =
Validation result table header
%w[ERROR].freeze
Class Method Summary collapse
-
.manifest_list(manifests) ⇒ Object
Builds a table of manifest information.
-
.table(header: [], data: [], format: 'table') ⇒ CliFormat::Presenter
Creates a presenter for given data.
-
.validation_result(results) ⇒ Object
Builds a table for manifest validation results.
-
.variable_list(variables) ⇒ Object
Builds a table of variable information.
Class Method Details
.manifest_list(manifests) ⇒ Object
Builds a table of manifest information
58 59 60 61 62 63 64 65 66 67 68 |
# 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') ⇒ CliFormat::Presenter
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’.
41 42 43 44 45 46 47 48 49 50 51 |
# 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) ⇒ Object
Builds a table for manifest validation results
93 94 95 96 97 98 99 100 101 102 |
# 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) ⇒ Object
Builds a table of variable information
75 76 77 78 79 80 81 82 83 84 85 86 |
# 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 |