Module: Beaker::Subcommands::SubcommandUtil
- Defined in:
- lib/beaker/subcommands/subcommand_util.rb
Overview
Methods used in execution of Subcommands
-
should we execute a subcommand?
-
reset ARGV
-
execute Beaker
-
update a rakefile to require beaker quickstart tasks
- initialise a rake application
-
execute a rake task
-
execute the vagrant quickstart task
-
execute the vmpooler quickstart task
-
exit with a specific message
-
verify that the init subcommand has the correct arguments
-
execute the quick start task for the specified hypervisor
Constant Summary collapse
- BEAKER_REQUIRE =
"require 'beaker/tasks/quick_start'"
- HYPERVISORS =
["vagrant", "vmpooler"]
Class Method Summary collapse
-
.determine_rake_file ⇒ String
Determines what Rakefile to use.
-
.execute_beaker(*args) ⇒ Object
Update ARGV and call Beaker @param [Array<String>] args the arguments determined by a specific subcommand.
-
.execute_rake_task(task) ⇒ Object
Clear ARGV and execute a Rake task @param [String] task the rake task to execute.
-
.execute_subcommand?(arg0) ⇒ Boolean
Check if the first argument to the beaker execution is a subcommand.
-
.exit_with(msg) ⇒ Object
Print a message to the console and exit with 0 @param [String] msg the message to print.
-
.init_hypervisor(options) ⇒ Object
Call the quick start task for the specified hypervisor.
-
.init_vagrant ⇒ Object
Execute the quick start task for vagrant.
-
.init_vmpooler ⇒ Object
Execute the quick start task for vmpooler.
-
.rake_app ⇒ Object
Initialises a rake application.
-
.require_tasks ⇒ Object
Check for the presence of a Rakefile containing the require of the quick start tasks.
-
.reset_argv(args) ⇒ Object
Reset ARGV to contain the arguments determined by a specific subcommand @param [Array<String>] args the arguments determined by a specific subcommand.
-
.verify_init_args(options) ⇒ Object
Verify that a valid hypervisor has been specified @param [Array<Object>] options the options we want to query.
Class Method Details
.determine_rake_file ⇒ String
Determines what Rakefile to use
46 47 48 |
# File 'lib/beaker/subcommands/subcommand_util.rb', line 46 def self.determine_rake_file() rake_app.find_rakefile_location() ? rake_app.find_rakefile_location()[0] : "Rakefile" end |
.execute_beaker(*args) ⇒ Object
Update ARGV and call Beaker @param [Array<String>] args the arguments determined by a specific subcommand
39 40 41 42 |
# File 'lib/beaker/subcommands/subcommand_util.rb', line 39 def self.execute_beaker(*args) reset_argv(args) Beaker::CLI.new.execute! end |
.execute_rake_task(task) ⇒ Object
Clear ARGV and execute a Rake task @param [String] task the rake task to execute
72 73 74 75 |
# File 'lib/beaker/subcommands/subcommand_util.rb', line 72 def self.execute_rake_task(task) rake_app.load_rakefile() rake_app.invoke_task(task) end |
.execute_subcommand?(arg0) ⇒ Boolean
Check if the first argument to the beaker execution is a subcommand
23 24 25 26 |
# File 'lib/beaker/subcommands/subcommand_util.rb', line 23 def self.execute_subcommand?(arg0) return false if arg0.nil? (Beaker::Subcommand.instance_methods(false) << :help).include? arg0.to_sym end |
.exit_with(msg) ⇒ Object
Print a message to the console and exit with 0 @param [String] msg the message to print
89 90 91 92 |
# File 'lib/beaker/subcommands/subcommand_util.rb', line 89 def self.exit_with(msg) puts msg exit(0) end |
.init_hypervisor(options) ⇒ Object
Call the quick start task for the specified hypervisor
104 105 106 107 108 109 110 111 |
# File 'lib/beaker/subcommands/subcommand_util.rb', line 104 def self.init_hypervisor() case [:hypervisor] when "vagrant" init_vagrant when "vmpooler" init_vmpooler end end |
.init_vagrant ⇒ Object
Execute the quick start task for vagrant
78 79 80 |
# File 'lib/beaker/subcommands/subcommand_util.rb', line 78 def self.init_vagrant() execute_rake_task("beaker_quickstart:gen_hosts[vagrant]") end |
.init_vmpooler ⇒ Object
Execute the quick start task for vmpooler
83 84 85 |
# File 'lib/beaker/subcommands/subcommand_util.rb', line 83 def self.init_vmpooler() execute_rake_task("beaker_quickstart:gen_hosts[vmpooler]") end |
.rake_app ⇒ Object
Initialises a rake application
61 62 63 64 65 66 67 68 |
# File 'lib/beaker/subcommands/subcommand_util.rb', line 61 def self.rake_app() unless @rake_app ARGV.clear @rake_app = Rake.application @rake_app.init end @rake_app end |
.require_tasks ⇒ Object
Check for the presence of a Rakefile containing the require of the quick start tasks
52 53 54 55 56 57 |
# File 'lib/beaker/subcommands/subcommand_util.rb', line 52 def self.require_tasks() rake_file = determine_rake_file() unless File.readlines(rake_file).grep(/#{BEAKER_REQUIRE}/).any? File.open(rake_file, "a+") { |f| f.puts(BEAKER_REQUIRE) } end end |
.reset_argv(args) ⇒ Object
Reset ARGV to contain the arguments determined by a specific subcommand @param [Array<String>] args the arguments determined by a specific subcommand
30 31 32 33 34 35 |
# File 'lib/beaker/subcommands/subcommand_util.rb', line 30 def self.reset_argv(args) ARGV.clear args.each do |arg| ARGV << arg end end |
.verify_init_args(options) ⇒ Object
Verify that a valid hypervisor has been specified @param [Array<Object>] options the options we want to query
96 97 98 99 100 |
# File 'lib/beaker/subcommands/subcommand_util.rb', line 96 def self.verify_init_args() unless HYPERVISORS.include?([:hypervisor]) exit_with("Invalid hypervisor. Currently supported hypervisors are: #{HYPERVISORS.join(', ')}") end end |