class Vcloud::NetLauncher::Cli
Public Class Methods
new(argv_array)
click to toggle source
Initiates parsing of the command-line arguments.
@param argv_array [Array] Command-line arguments @return [void]
# File lib/vcloud/net_launcher/cli.rb, line 11 def initialize(argv_array) @usage_text = nil @config_file = nil parse(argv_array) end
Public Instance Methods
run()
click to toggle source
Runs +Vcloud::NetLauncher::NetLaunch#run+ to create networks defined in +@config_file+, catching any exceptions to prevent printing a backtrace.
@return [void]
# File lib/vcloud/net_launcher/cli.rb, line 22 def run begin Vcloud::NetLauncher::NetLaunch.new.run(@config_file) rescue => error_msg $stderr.puts(error_msg) exit 1 end end
Private Instance Methods
exit_error_usage(error)
click to toggle source
# File lib/vcloud/net_launcher/cli.rb, line 82 def exit_error_usage(error) $stderr.puts "#{$0}: #{error}" $stderr.puts @usage_text exit 2 end
parse(args)
click to toggle source
# File lib/vcloud/net_launcher/cli.rb, line 33 def parse(args) opt_parser = OptionParser.new do |opts| examples_dir = File.absolute_path( File.join( File.dirname(__FILE__), "..", "..", "..", "examples", File.basename($0), )) opts.banner = <<-EOS Usage: #{$0} [options] config_file vcloud-net-launch takes a configuration describing a vCloud network, and tries to make it a reality. See https://github.com/gds-operations/vcloud-tools for more info Example configuration files can be found in: #{examples_dir} EOS opts.separator "" opts.separator "Options:" opts.on("-h", "--help", "Print usage and exit") do $stderr.puts opts exit end opts.on("--version", "Display version and exit") do puts Vcloud::NetLauncher::VERSION exit end end @usage_text = opt_parser.to_s begin opt_parser.parse!(args) rescue OptionParser::InvalidOption => e exit_error_usage(e) end exit_error_usage("must supply config_file") unless args.size == 1 @config_file = args.first end