Class: Chronicle::ETL::CLI::Plugins

Inherits:
SubcommandBase show all
Defined in:
lib/chronicle/etl/cli/plugins.rb

Overview

CLI commands for working with ETL plugins

Instance Method Summary collapse

Methods inherited from SubcommandBase

banner, help, subcommand_prefix

Instance Method Details

#install(*plugins) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/chronicle/etl/cli/plugins.rb', line 15

def install(*plugins)
  cli_fail(message: 'Please specify a plugin to install') unless plugins.any?

  installed, not_installed = plugins.partition do |plugin|
    Chronicle::ETL::Registry::Plugins.installed?(plugin)
  end

  puts "Already installed: #{installed.join(', ')}" if installed.any?
  cli_exit unless not_installed.any?

  spinner = TTY::Spinner.new("[:spinner] Installing #{not_installed.join(', ')}...", format: :dots_2)
  spinner.auto_spin

  not_installed.each do |plugin|
    spinner.update(title: "Installing #{plugin}")
    Chronicle::ETL::Registry::Plugins.install(plugin)
  rescue Chronicle::ETL::PluginError => e
    spinner.error('Error'.red)
    cli_fail(message: "Plugin '#{plugin}' could not be installed", exception: e)
  end

  spinner.success("(#{'successful'.green})")
end

#listObject

Display all available plugins that chronicle-etl has access to



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/chronicle/etl/cli/plugins.rb', line 52

def list
  values = Chronicle::ETL::Registry::Plugins.all
    .map do |plugin|
    [
      plugin.name,
      plugin.description,
      plugin.installed ? '' : '',
      plugin.version
    ]
  end

  headers = %w[name description installed version].map { |h| h.to_s.upcase.bold }
  table = TTY::Table.new(headers, values)
  puts 'Available plugins:'
  puts table.render(
    indent: 2,
    padding: [0, 0],
    alignments: %i[left left center left]
  )
end

#uninstall(name) ⇒ Object



40
41
42
43
44
45
46
47
48
# File 'lib/chronicle/etl/cli/plugins.rb', line 40

def uninstall(name)
  spinner = TTY::Spinner.new("[:spinner] Uninstalling plugin #{name}...", format: :dots_2)
  spinner.auto_spin
  Chronicle::ETL::Registry::Plugins.uninstall(name)
  spinner.success("(#{'successful'.green})")
rescue Chronicle::ETL::PluginError => e
  spinner.error('Error'.red)
  cli_fail(message: "Plugin '#{name}' could not be uninstalled (was it installed?)", exception: e)
end