core: output synopsis with command [GH-2249]

This commit is contained in:
Mitchell Hashimoto 2013-11-23 14:00:42 -08:00
parent 844c672911
commit 97389d4255
17 changed files with 80 additions and 11 deletions

View File

@ -55,13 +55,16 @@ module Vagrant
# Add the available subcommands as separators in order to print them
# out as well.
keys = []
Vagrant.plugin("2").manager.commands.each do |key, _|
keys << key
commands = {}
longest = 0
Vagrant.plugin("2").manager.commands.each do |key, klass|
key = key.to_s
commands[key] = klass.synopsis
longest = key.length if key.length > longest
end
keys.sort.each do |key|
o.separator " #{key}"
commands.keys.sort.each do |key|
o.separator " #{key.ljust(longest+2)} #{commands[key]}"
end
o.separator ""

View File

@ -9,6 +9,14 @@ module Vagrant
class Command
include Util::SafePuts
# This should return a brief (60 characters or less) synopsis of what
# this command does. It will be used in the output of the help.
#
# @return [String]
def self.synopsis
""
end
def initialize(argv, env)
@argv = argv
@env = env

View File

@ -4,6 +4,10 @@ module VagrantPlugins
module CommandBox
module Command
class Root < Vagrant.plugin("2", :command)
def self.synopsis
"manages boxes: installation, removal, etc."
end
def initialize(argv, env)
super

View File

@ -1,6 +1,10 @@
module VagrantPlugins
module CommandDestroy
class Command < Vagrant.plugin("2", :command)
def self.synopsis
"stops and deletes all traces of the vagrant machine"
end
def execute
options = {}
options[:force] = false

View File

@ -3,6 +3,10 @@ require 'optparse'
module VagrantPlugins
module CommandHalt
class Command < Vagrant.plugin("2", :command)
def self.synopsis
"stops the vagrant machine"
end
def execute
options = {}
options[:force] = false

View File

@ -3,6 +3,10 @@ require 'optparse'
module VagrantPlugins
module CommandHelp
class Command < Vagrant.plugin("2", :command)
def self.synopsis
"shows the help for a subcommand"
end
def execute
return @env.cli([]) if @argv.empty?
@env.cli([@argv[0], "-h"])

View File

@ -5,11 +5,13 @@ require 'vagrant/util/template_renderer'
module VagrantPlugins
module CommandInit
class Command < Vagrant.plugin("2", :command)
def execute
options = {}
def self.synopsis
"initializes a new Vagrant environment by creating a Vagrantfile"
end
opts = OptionParser.new do |opts|
opts.banner = "Usage: vagrant init [box-name] [box-url]"
def execute
opts = OptionParser.new do |o|
o.banner = "Usage: vagrant init [box-name] [box-url]"
end
# Parse the options
@ -34,7 +36,7 @@ module VagrantPlugins
# Success, exit status 0
0
end
end
end
end
end

View File

@ -3,6 +3,10 @@ require 'optparse'
module VagrantPlugins
module CommandPackage
class Command < Vagrant.plugin("2", :command)
def self.synopsis
"packages a running vagrant environment into a box"
end
def execute
options = {}

View File

@ -4,6 +4,10 @@ module VagrantPlugins
module CommandPlugin
module Command
class Root < Vagrant.plugin("2", :command)
def self.synopsis
"manages plugins: install, uninstall, update, etc."
end
def initialize(argv, env)
super

View File

@ -3,6 +3,10 @@ require 'optparse'
module VagrantPlugins
module CommandProvision
class Command < Vagrant.plugin("2", :command)
def self.synopsis
"provisions the vagrant machine"
end
def execute
options = {}
options[:provision_types] = nil

View File

@ -11,6 +11,10 @@ module VagrantPlugins
# to this.
include VagrantPlugins::CommandUp::StartMixins
def self.synopsis
"restarts vagrant machine, loads new Vagrantfile configuration"
end
def execute
options = {}
options[:provision_ignore_sentinel] = false

View File

@ -3,6 +3,10 @@ require 'optparse'
module VagrantPlugins
module CommandResume
class Command < Vagrant.plugin("2", :command)
def self.synopsis
"resume a suspended vagrant machine"
end
def execute
opts = OptionParser.new do |o|
o.banner = "Usage: vagrant resume [vm-name]"

View File

@ -3,6 +3,10 @@ require 'optparse'
module VagrantPlugins
module CommandSSH
class Command < Vagrant.plugin("2", :command)
def self.synopsis
"connects to machine via SSH"
end
def execute
options = {}

View File

@ -7,6 +7,10 @@ module VagrantPlugins
class Command < Vagrant.plugin("2", :command)
include Vagrant::Util::SafePuts
def self.synopsis
"outputs OpenSSH valid configuration to connect to the machine"
end
def execute
options = {}

View File

@ -3,6 +3,10 @@ require 'optparse'
module VagrantPlugins
module CommandStatus
class Command < Vagrant.plugin("2", :command)
def self.synopsis
"outputs status of the vagrant machine"
end
def execute
opts = OptionParser.new do |o|
o.banner = "Usage: vagrant status [machine-name]"

View File

@ -3,6 +3,10 @@ require 'optparse'
module VagrantPlugins
module CommandSuspend
class Command < Vagrant.plugin("2", :command)
def self.synopsis
"suspends the machine"
end
def execute
opts = OptionParser.new do |o|
o.banner = "Usage: vagrant suspend [vm-name]"

View File

@ -9,6 +9,10 @@ module VagrantPlugins
class Command < Vagrant.plugin("2", :command)
include StartMixins
def self.synopsis
"starts and provisions the vagrant environment"
end
def execute
options = {}
options[:destroy_on_error] = true