commands/global-status: initial go at it
This commit is contained in:
parent
48cf2c38f7
commit
e14216da4e
|
@ -0,0 +1,80 @@
|
||||||
|
require 'optparse'
|
||||||
|
|
||||||
|
module VagrantPlugins
|
||||||
|
module CommandGlobalStatus
|
||||||
|
class Command < Vagrant.plugin("2", :command)
|
||||||
|
def self.synopsis
|
||||||
|
"outputs status Vagrant environments for this user"
|
||||||
|
end
|
||||||
|
|
||||||
|
def execute
|
||||||
|
opts = OptionParser.new do |o|
|
||||||
|
o.banner = "Usage: vagrant global-status"
|
||||||
|
end
|
||||||
|
|
||||||
|
# Parse the options
|
||||||
|
argv = parse_options(opts)
|
||||||
|
return if !argv
|
||||||
|
|
||||||
|
columns = [
|
||||||
|
["id", :id],
|
||||||
|
["name", :name],
|
||||||
|
["provider", :provider],
|
||||||
|
["state", :state],
|
||||||
|
["directory", :vagrantfile_path],
|
||||||
|
]
|
||||||
|
|
||||||
|
widths = {}
|
||||||
|
widths[:id] = 8
|
||||||
|
widths[:name] = 6
|
||||||
|
widths[:provider] = 6
|
||||||
|
widths[:state] = 6
|
||||||
|
widths[:vagrantfile_path] = 35
|
||||||
|
|
||||||
|
entries = []
|
||||||
|
@env.machine_index.each do |entry|
|
||||||
|
entries << entry
|
||||||
|
|
||||||
|
columns.each do |_, method|
|
||||||
|
# Skip the id
|
||||||
|
next if method == :id
|
||||||
|
|
||||||
|
widths[method] ||= 0
|
||||||
|
cur = entry.send(method).to_s.length
|
||||||
|
widths[method] = cur if cur > widths[method]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
total_width = 0
|
||||||
|
columns.each do |header, method|
|
||||||
|
header = header.ljust(widths[method]) if widths[method]
|
||||||
|
@env.ui.info("#{header} ", new_line: false)
|
||||||
|
total_width += header.length + 1
|
||||||
|
end
|
||||||
|
@env.ui.info("")
|
||||||
|
@env.ui.info("-" * total_width)
|
||||||
|
|
||||||
|
if entries.empty?
|
||||||
|
@env.ui.info(I18n.t("vagrant.global_status_none"))
|
||||||
|
return 0
|
||||||
|
end
|
||||||
|
|
||||||
|
entries.each do |entry|
|
||||||
|
columns.each do |_, method|
|
||||||
|
v = entry.send(method).to_s
|
||||||
|
v = v[0...7] if method == :id
|
||||||
|
v = v.ljust(widths[method]) if widths[method]
|
||||||
|
@env.ui.info("#{v} ", new_line: false)
|
||||||
|
end
|
||||||
|
|
||||||
|
@env.ui.info("")
|
||||||
|
end
|
||||||
|
|
||||||
|
@env.ui.info(" \n" + I18n.t("vagrant.global_status_footer"))
|
||||||
|
|
||||||
|
# Success, exit status 0
|
||||||
|
0
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -0,0 +1,18 @@
|
||||||
|
require "vagrant"
|
||||||
|
|
||||||
|
module VagrantPlugins
|
||||||
|
module CommandGlobalStatus
|
||||||
|
class Plugin < Vagrant.plugin("2")
|
||||||
|
name "global-status command"
|
||||||
|
description <<-DESC
|
||||||
|
The `global-status` command shows what the running state (running/saved/..)
|
||||||
|
is of all the Vagrant environments known to the system.
|
||||||
|
DESC
|
||||||
|
|
||||||
|
command("global-status") do
|
||||||
|
require File.expand_path("../command", __FILE__)
|
||||||
|
Command
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -137,6 +137,17 @@ en:
|
||||||
description of what they do.
|
description of what they do.
|
||||||
|
|
||||||
%{list}
|
%{list}
|
||||||
|
global_status_footer: |-
|
||||||
|
The above shows information about all known Vagrant environments
|
||||||
|
on this machine. This data is cached and may not be completely
|
||||||
|
up-to-date. To interact with any of the machines, you can go to
|
||||||
|
that directory and run Vagrant, or you can use the ID directly
|
||||||
|
with Vagrant commands from any directory. For example:
|
||||||
|
"vagrant destroy 1a2b3c4d"
|
||||||
|
global_status_none: |-
|
||||||
|
There are no active Vagrant environments on this computer! Or,
|
||||||
|
you haven't destroyed and recreated Vagrant environments that were
|
||||||
|
started with an older version of Vagrant.
|
||||||
plugin_needs_reinstall: |-
|
plugin_needs_reinstall: |-
|
||||||
The following plugins were installed with a version of Vagrant
|
The following plugins were installed with a version of Vagrant
|
||||||
that had different versions of underlying components. Because
|
that had different versions of underlying components. Because
|
||||||
|
|
Loading…
Reference in New Issue