Skip to content
This repository has been archived by the owner on Nov 2, 2019. It is now read-only.

Commit

Permalink
Some updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Demitri Swan committed Jun 12, 2015
1 parent e75f332 commit 249444b
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 37 deletions.
39 changes: 35 additions & 4 deletions lib/command.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,46 @@
#!/usr/bin/env ruby

module Vbinfo
class Command
include Vbinfo::Helpers
# Helper functions
module Helpers
# Return an array of vm IDs for the vagrant project in the
# current directory
def ids
i = []
Find.find("#{ENV['PWD']}/.vagrant") do |item|
if File.file?(item) and File.basename(item) == 'id'
id = File.open(item).read
i << id
end
end
return i
end

# Print detailed info for the given VM ID
def get_info(id)
# Fail if vboxmanage does not exist in the path
check = Mixlib::ShellOut.new("which vboxmanage")
check.run_command
if check.stdout.empty?
assert Vagrant::Errors::VagrantError::CommandUnavailable, file: 'vboxmanage'
exit 1
end
# Return the output
output = Mixlib::ShellOut.new("vboxmanage showvminfo #{id}")
output.run_command
return output.stdout
end
end

class Command
include Helpers
# Print detailed information for each Virtualbox VM associated with
# the project in the current directory
def execute
ids.each do |id|
get_info(id)
puts "#{get_info(id).to_s}\n\n"
end
exit 0
end

end
end
2 changes: 2 additions & 0 deletions lib/command/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env ruby

module Vbinfo
VERSION = "0.0.1"
end
39 changes: 6 additions & 33 deletions lib/plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,40 +6,13 @@


module Vbinfo
module CommandVbinfo
module Helpers
def ids
i = []
Find.find("#{ENV['PWD']}/.vagrant") do |item|
if File.file?(item) and File.basename(item) == 'id'
id = File.open(item).read
i << id
end
end
return i
end
class VBinfo < Vagrant.plugin(2, :command)
name "vbinfo command"
description "The `vbinfo` command gives you detailed information for configured virtualbox vms"

def get_info(id)
check = Mixlib::ShellOut.new("which vboxmanage")
check.run_command
if check.stdout.empty?
assert Vagrant::Errors::VagrantError::CommandUnavailable, file: 'vboxmanage'
exit 1
end
output = Mixlib::ShellOut.new("vboxmanage showvminfo #{id}")
output.run_command
return output.stdout
end
end

class VBinfo < Vagrant.plugin(2, :command)
name "vbinfo command"
description "The `vbinfo` command gives you detailed information for configured virtualbox vms"

command "vbinfo" do
require_relative 'command'
Vbinfo::Command
end
command "vbinfo" do
require_relative 'command'
Vbinfo::Command
end
end
end
Expand Down

0 comments on commit 249444b

Please sign in to comment.