vagrant/plugins/commands/box/command/list.rb

50 lines
1.5 KiB
Ruby
Raw Normal View History

2012-04-19 20:59:48 +00:00
require 'optparse'
module VagrantPlugins
module CommandBox
module Command
2012-11-07 05:05:14 +00:00
class List < Vagrant.plugin("2", :command)
2012-04-19 20:59:48 +00:00
def execute
options = {}
opts = OptionParser.new do |opts|
opts.banner = "Usage: vagrant box list"
end
# Parse the options
argv = parse_options(opts)
return if !argv
boxes = @env.boxes.all.sort
2012-04-19 20:59:48 +00:00
if boxes.empty?
return @env.ui.warn(I18n.t("vagrant.commands.box.no_installed_boxes"), :prefix => false)
end
# Find the longest box name
longest_box = boxes.max_by { |x| x[0].length }
longest_box_length = longest_box[0].length
# Find the longest provider name
longest_provider = boxes.max_by { |x| x[1].length }
longest_provider_length = longest_provider[1].length
# Go through each box and output the information about it. We
# ignore the "v1" param for now since I'm not yet sure if its
# important for the user to know what boxes need to be upgraded
# and which don't, since we plan on doing that transparently.
boxes.each do |name, provider, _v1|
name = name.ljust(longest_box_length)
provider = "(#{provider})".ljust(longest_provider_length + 2) # 2 -> parenthesis
box_info = "#{name} #{provider}"
@env.ui.info(box_info, :prefix => false)
end
2012-04-19 20:59:48 +00:00
# Success, exit status 0
0
end
end
end
end
end