Class: VagrantSpec::Command::Base
- Inherits:
-
Object
- Object
- VagrantSpec::Command::Base
- Defined in:
- lib/vagrant_spec/command/base.rb
Overview
This command plugin routes to the available subcommands
Instance Attribute Summary collapse
-
#env ⇒ Object
Returns the value of attribute env.
-
#opts ⇒ Object
Returns the value of attribute opts.
-
#subcommands ⇒ Object
Returns the value of attribute subcommands.
-
#valid_commands ⇒ Object
Returns the value of attribute valid_commands.
Class Method Summary collapse
Instance Method Summary collapse
- #execute ⇒ Object
- #help ⇒ Object
-
#initialize(argv, env) ⇒ Base
constructor
A new instance of Base.
- #parse_main_args ⇒ Object
- #parse_subcommand ⇒ Object
- #print_help ⇒ Object
- #register_subcommands ⇒ Object
Constructor Details
#initialize(argv, env) ⇒ Base
Returns a new instance of Base.
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/vagrant_spec/command/base.rb', line 12 def initialize(argv, env) super @main_args, @sub_command, @sub_args = split_main_and_subcommand(argv) @valid_commands = Dir.glob(File.join(File.dirname(__FILE__), '*')) .collect { |f| File.basename(f).gsub(/\.rb$/, '') } .select { |f| f != 'base' } @subcommands = Vagrant::Registry.new @env = env @opts = nil end |
Instance Attribute Details
#env ⇒ Object
Returns the value of attribute env.
11 12 13 |
# File 'lib/vagrant_spec/command/base.rb', line 11 def env @env end |
#opts ⇒ Object
Returns the value of attribute opts.
11 12 13 |
# File 'lib/vagrant_spec/command/base.rb', line 11 def opts @opts end |
#subcommands ⇒ Object
Returns the value of attribute subcommands.
11 12 13 |
# File 'lib/vagrant_spec/command/base.rb', line 11 def subcommands @subcommands end |
#valid_commands ⇒ Object
Returns the value of attribute valid_commands.
11 12 13 |
# File 'lib/vagrant_spec/command/base.rb', line 11 def valid_commands @valid_commands end |
Class Method Details
.synopsis ⇒ Object
7 8 9 |
# File 'lib/vagrant_spec/command/base.rb', line 7 def self.synopsis 'test deployments to clustered systems' end |
Instance Method Details
#execute ⇒ Object
25 26 27 28 29 |
# File 'lib/vagrant_spec/command/base.rb', line 25 def execute register_subcommands return unless parse_main_args return unless parse_subcommand end |
#help ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/vagrant_spec/command/base.rb', line 41 def help opts = OptionParser.new do |o| o. = "\nUsage: vagrant spec <command> [<args>]" o.separator '' o.separator 'Available subcommands:' @valid_commands.sort.each { |cmd| o.separator " #{cmd}" } o.separator '' o.separator 'For help on any individual command run `vagrant spec ' \ '<command> -h`' end (opts) && @opts = opts end |
#parse_main_args ⇒ Object
59 60 61 62 63 64 |
# File 'lib/vagrant_spec/command/base.rb', line 59 def parse_main_args if @main_args.include?('-h') || @main_args.include?('--help') return help end true end |
#parse_subcommand ⇒ Object
66 67 68 69 70 71 |
# File 'lib/vagrant_spec/command/base.rb', line 66 def parse_subcommand klass = @subcommands.get(@sub_command.to_sym) if @sub_command return print_help if @sub_command.nil? || klass.nil? klass.new(@sub_args, @env).execute true end |
#print_help ⇒ Object
54 55 56 57 |
# File 'lib/vagrant_spec/command/base.rb', line 54 def print_help help @env.ui.info @opts end |
#register_subcommands ⇒ Object
31 32 33 34 35 36 37 38 39 |
# File 'lib/vagrant_spec/command/base.rb', line 31 def register_subcommands @valid_commands.each do |cmd| @subcommands.register cmd.to_sym do cmd_str = cmd.to_s require "vagrant_spec/command/#{cmd_str}" Object.const_get "VagrantSpec::Command::#{cmd_str.capitalize}" end end end |