class Bosh::Cli::PublicStemcellPresenter

Public Class Methods

new(ui, public_stemcells) click to toggle source
# File lib/cli/public_stemcell_presenter.rb, line 5
def initialize(ui, public_stemcells)
  @ui = ui
  @public_stemcells = public_stemcells
end

Public Instance Methods

download(stemcell_name) click to toggle source
# File lib/cli/public_stemcell_presenter.rb, line 24
def download(stemcell_name)
  unless @public_stemcells.has_stemcell?(stemcell_name)
    @ui.err("'#{stemcell_name}' not found.")
  end

  if File.exists?(stemcell_name) && !@ui.confirmed?("Overwrite existing file `#{stemcell_name}'?")
    @ui.err("File `#{stemcell_name}' already exists")
  end

  stemcell = @public_stemcells.find(stemcell_name)
  download_with_progress = DownloadWithProgress.new(stemcell.url, stemcell.size)
  download_with_progress.perform

  @ui.say('Download complete'.make_green)
end
list(options) click to toggle source
# File lib/cli/public_stemcell_presenter.rb, line 10
def list(options)
  full = !!options[:full]
  stemcells_table = @ui.table do |t|
    t.headings = full ? %w(Name Url) : %w(Name)

    stemcell_for(options).each do |stemcell|
      t << (full ? [stemcell.name, stemcell.url] : [stemcell.name])
    end
  end

  @ui.say(stemcells_table.render)
  @ui.say("To download use `bosh download public stemcell <stemcell_name>'. For full url use --full.")
end

Private Instance Methods

stemcell_for(options) click to toggle source
# File lib/cli/public_stemcell_presenter.rb, line 42
def stemcell_for(options)
  options[:all] ? @public_stemcells.all : @public_stemcells.recent
end