Sha256: 487ea04b24a5912527785888c69325e68d8e2cf5b80b51e3736226e426cd184d

Contents?: true

Size: 1.56 KB

Versions: 34

Compression:

Stored size: 1.56 KB

Contents

require 'kontena/plugin_manager'
require_relative 'common'

module Kontena::Cli::Plugins
  class UpgradeCommand < Kontena::Command
    include Kontena::Cli::Common
    include Common
    include Kontena::PluginManager::Common

    option '--pre', :flag, 'Include pre-release versions'
    option '--silent', :flag, 'Less verbose output'

    def running_verbose?
      !silent?
    end

    def cleanup(*plugins)
      return if plugins.empty?
      vspinner "Running cleanup" do
        plugins.each do |name|
          Kontena::PluginManager::Cleaner.new(name).cleanup
        end
      end
    end

    def installer(name, version: nil)
      Kontena::PluginManager::Installer.new(name, pre: pre?, version: version)
    end

    def upgrade(name, from, to)
      vspinner "Upgrading #{pastel.cyan(name)} from #{pastel.cyan(from)} to #{pastel.cyan(to)}" do
        installer(name, version: to).install
      end
      sputs "Upgraded #{name} from #{from} to #{to}" if silent?
    end

    def execute
      upgradable = {}

      vspinner "Checking for upgrades" do
        plugins.each do |plugin|
          short = short_name(plugin.name)
          available_upgrade = installer(short).available_upgrade
          unless available_upgrade.nil?
            upgradable[short] = { from: plugin.version.to_s, to: available_upgrade }
          end
        end
      end

      if upgradable.empty?
        vputs "Nothing upgraded"
      else
        upgradable.each do |name, data|
          upgrade(name, data[:from], data[:to])
        end
        cleanup(upgradable.keys)
      end
    end
  end
end

Version data entries

34 entries across 34 versions & 2 rubygems

Version Path
krates-1.7.11 lib/kontena/cli/plugins/upgrade_command.rb
krates-1.7.10 lib/kontena/cli/plugins/upgrade_command.rb
krates-1.7.9 lib/kontena/cli/plugins/upgrade_command.rb
krates-1.7.8 lib/kontena/cli/plugins/upgrade_command.rb
krates-1.7.7 lib/kontena/cli/plugins/upgrade_command.rb
krates-1.7.6 lib/kontena/cli/plugins/upgrade_command.rb
krates-1.7.5 lib/kontena/cli/plugins/upgrade_command.rb
krates-1.7.4 lib/kontena/cli/plugins/upgrade_command.rb
krates-1.7.3 lib/kontena/cli/plugins/upgrade_command.rb
krates-1.7.2 lib/kontena/cli/plugins/upgrade_command.rb
krates-1.7.1 lib/kontena/cli/plugins/upgrade_command.rb
krates-1.7.0 lib/kontena/cli/plugins/upgrade_command.rb
krates-1.6.9 lib/kontena/cli/plugins/upgrade_command.rb
krates-1.6.8 lib/kontena/cli/plugins/upgrade_command.rb
krates-1.6.7 lib/kontena/cli/plugins/upgrade_command.rb
krates-1.6.6 lib/kontena/cli/plugins/upgrade_command.rb
krates-1.6.5 lib/kontena/cli/plugins/upgrade_command.rb
krates-1.6.4 lib/kontena/cli/plugins/upgrade_command.rb
krates-1.6.3 lib/kontena/cli/plugins/upgrade_command.rb
krates-1.6.2 lib/kontena/cli/plugins/upgrade_command.rb