From 97389d42553dcd344c3c6ba602a31753b0847594 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sat, 23 Nov 2013 14:00:42 -0800 Subject: [PATCH] core: output synopsis with command [GH-2249] --- lib/vagrant/cli.rb | 13 ++++++++----- lib/vagrant/plugin/v2/command.rb | 8 ++++++++ plugins/commands/box/command/root.rb | 4 ++++ plugins/commands/destroy/command.rb | 4 ++++ plugins/commands/halt/command.rb | 4 ++++ plugins/commands/help/command.rb | 4 ++++ plugins/commands/init/command.rb | 12 +++++++----- plugins/commands/package/command.rb | 4 ++++ plugins/commands/plugin/command/root.rb | 4 ++++ plugins/commands/provision/command.rb | 6 +++++- plugins/commands/reload/command.rb | 4 ++++ plugins/commands/resume/command.rb | 4 ++++ plugins/commands/ssh/command.rb | 4 ++++ plugins/commands/ssh_config/command.rb | 4 ++++ plugins/commands/status/command.rb | 4 ++++ plugins/commands/suspend/command.rb | 4 ++++ plugins/commands/up/command.rb | 4 ++++ 17 files changed, 80 insertions(+), 11 deletions(-) diff --git a/lib/vagrant/cli.rb b/lib/vagrant/cli.rb index d771300c7..112c27adf 100644 --- a/lib/vagrant/cli.rb +++ b/lib/vagrant/cli.rb @@ -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 "" diff --git a/lib/vagrant/plugin/v2/command.rb b/lib/vagrant/plugin/v2/command.rb index 918225974..ebee926e3 100644 --- a/lib/vagrant/plugin/v2/command.rb +++ b/lib/vagrant/plugin/v2/command.rb @@ -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 diff --git a/plugins/commands/box/command/root.rb b/plugins/commands/box/command/root.rb index c8589b7da..4150fd659 100644 --- a/plugins/commands/box/command/root.rb +++ b/plugins/commands/box/command/root.rb @@ -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 diff --git a/plugins/commands/destroy/command.rb b/plugins/commands/destroy/command.rb index e4ac0d6a1..efb78f6d1 100644 --- a/plugins/commands/destroy/command.rb +++ b/plugins/commands/destroy/command.rb @@ -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 diff --git a/plugins/commands/halt/command.rb b/plugins/commands/halt/command.rb index 3c09f558a..b883985a0 100644 --- a/plugins/commands/halt/command.rb +++ b/plugins/commands/halt/command.rb @@ -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 diff --git a/plugins/commands/help/command.rb b/plugins/commands/help/command.rb index 08a847177..0ce4d8598 100644 --- a/plugins/commands/help/command.rb +++ b/plugins/commands/help/command.rb @@ -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"]) diff --git a/plugins/commands/init/command.rb b/plugins/commands/init/command.rb index aaf4f0d8d..1b644b4cd 100644 --- a/plugins/commands/init/command.rb +++ b/plugins/commands/init/command.rb @@ -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 diff --git a/plugins/commands/package/command.rb b/plugins/commands/package/command.rb index 445d905c1..255c6f95e 100644 --- a/plugins/commands/package/command.rb +++ b/plugins/commands/package/command.rb @@ -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 = {} diff --git a/plugins/commands/plugin/command/root.rb b/plugins/commands/plugin/command/root.rb index 1bef44894..c3675fb93 100644 --- a/plugins/commands/plugin/command/root.rb +++ b/plugins/commands/plugin/command/root.rb @@ -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 diff --git a/plugins/commands/provision/command.rb b/plugins/commands/provision/command.rb index 563ae66f4..f05607158 100644 --- a/plugins/commands/provision/command.rb +++ b/plugins/commands/provision/command.rb @@ -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 @@ -14,7 +18,7 @@ module VagrantPlugins "Enable only certain provisioners, by type.") do |list| options[:provision_types] = list.map { |type| type.to_sym } end - + o.on("--[no-]parallel", "Enable or disable parallelism if provider supports it.") do |parallel| options[:parallel] = parallel diff --git a/plugins/commands/reload/command.rb b/plugins/commands/reload/command.rb index 73714af27..1c27d817f 100644 --- a/plugins/commands/reload/command.rb +++ b/plugins/commands/reload/command.rb @@ -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 diff --git a/plugins/commands/resume/command.rb b/plugins/commands/resume/command.rb index 92b544918..18e1aa208 100644 --- a/plugins/commands/resume/command.rb +++ b/plugins/commands/resume/command.rb @@ -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]" diff --git a/plugins/commands/ssh/command.rb b/plugins/commands/ssh/command.rb index f0dc897bc..276093395 100644 --- a/plugins/commands/ssh/command.rb +++ b/plugins/commands/ssh/command.rb @@ -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 = {} diff --git a/plugins/commands/ssh_config/command.rb b/plugins/commands/ssh_config/command.rb index e1943b2c5..7ebae73fd 100644 --- a/plugins/commands/ssh_config/command.rb +++ b/plugins/commands/ssh_config/command.rb @@ -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 = {} diff --git a/plugins/commands/status/command.rb b/plugins/commands/status/command.rb index 722ba0819..9dc5fb724 100644 --- a/plugins/commands/status/command.rb +++ b/plugins/commands/status/command.rb @@ -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]" diff --git a/plugins/commands/suspend/command.rb b/plugins/commands/suspend/command.rb index 7e33f819d..66f3ea22b 100644 --- a/plugins/commands/suspend/command.rb +++ b/plugins/commands/suspend/command.rb @@ -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]" diff --git a/plugins/commands/up/command.rb b/plugins/commands/up/command.rb index b4f765d5e..5d5a47a0f 100644 --- a/plugins/commands/up/command.rb +++ b/plugins/commands/up/command.rb @@ -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