Class: Pcli::Services::Commands::Templates::List

Inherits:
Dry::CLI::Command
  • Object
show all
Defined in:
lib/pcli/services/commands/templates/list.rb

Instance Method Summary collapse

Instance Method Details

#callObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/pcli/services/commands/templates/list.rb', line 17

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