Module: Kontena::Cli::TableGenerator::Helper
- Included in:
- Certificate::DomainAuthorization::ListCommand, Certificate::ListCommand, Cloud::Master::ListCommand, Containers::ListCommand, ExternalRegistries::ListCommand, Grids::ListCommand, Grids::Users::ListCommand, Master::ListCommand, Master::Token::ListCommand, Master::User::ListCommand, Nodes::ListCommand, Plugins::ListCommand, Services::Envs::ListCommand, Services::ListCommand, Stacks::ListCommand, Stacks::Registry::SearchCommand, Vault::ListCommand, Volumes::ListCommand
- Defined in:
- lib/kontena/cli/table_generator.rb
Class Method Summary collapse
Instance Method Summary collapse
- #generate_table(array, fields = nil, &block) ⇒ Object
- #print_table(array, fields = nil, &block) ⇒ Object
- #table_generator ⇒ Object
Class Method Details
.included(base) ⇒ Object
17 18 19 20 21 |
# File 'lib/kontena/cli/table_generator.rb', line 17 def self.included(base) if base.respond_to?(:option) base.option ['-q', '--quiet'], :flag, "Output the identifying column only" end end |
Instance Method Details
#generate_table(array, fields = nil, &block) ⇒ Object
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/kontena/cli/table_generator.rb', line 27 def generate_table(array, fields = nil, &block) fields ||= self.fields if self.respond_to?(:fields) table_generator.new( array, fields, row_format_proc: block_given? ? block.to_proc : nil, header_format_proc: lambda { |item| pastel.bold(item.to_s.upcase) }, render_options: self.respond_to?(:render_options) ? DEFAULT_RENDER_OPTS.merge(self.) : DEFAULT_RENDER_OPTS ).render end |
#print_table(array, fields = nil, &block) ⇒ Object
38 39 40 41 |
# File 'lib/kontena/cli/table_generator.rb', line 38 def print_table(array, fields = nil, &block) output = generate_table(array, fields, &block) puts output unless output.strip.empty? end |
#table_generator ⇒ Object
23 24 25 |
# File 'lib/kontena/cli/table_generator.rb', line 23 def table_generator Kontena::Cli::TableGenerator end |