Sha256: 223b470e77f47a7fa40e176ef1d63240e73c4dee8a8ad76d941f4163904df27a

Contents?: true

Size: 1.25 KB

Versions: 2

Compression:

Stored size: 1.25 KB

Contents

# frozen_string_literal: true

module Pcli
  module Services
    module Commands
      module Templates
        class List < Dry::CLI::Command
          include Depends.on(
            'api',
            'api_manager',
            'output',
            'screen'
          )

          desc 'Get a list of all templates.'

          def call(*)
            spinner = nil
            response = api_manager.ensure_authenticated do
              spinner = SimpleSpinnerBar.start('Retrieving templates...', output)
              r = api.templates
              if r.failure?
                spinner.failure
              else
                spinner.success
              end
              r
            end

            if response.success?
              spinner.success
              output.puts
              output.puts TTY::Table.new(
                header: [
                  Pl.bold('ID'), Pl.bold('Name')
                ],
                rows: response.json.map { |u| [u['id'], u['name']] }
              ).render(:ascii)
            else
              spinner.failure

              output.puts
              Output::ServerError.show(response, output, screen)
            end

            CommandOutput.continue
          end
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
pcli-0.1.1 lib/pcli/services/commands/templates/list.rb
pcli-0.1.0 lib/pcli/services/commands/templates/list.rb