def process_options(options)
OptionParser.new do |opts|
program = File.basename($0)
opts.banner = <<EOB
Usage: #{program} [appliance definition file] [options]
A tool for building VM images from simple definition files.
Homepage:
http://boxgrinder.org/
Documentation:
http://boxgrinder.org/tutorials/
Examples:
$ #{program} jeos.appl # Build KVM image for jeos.appl
$ #{program} jeos.appl -f # Build KVM image for jeos.appl with removing previous build for this image
$ #{program} jeos.appl --os-config format:qcow2 # Build KVM image for jeos.appl with a qcow2 disk
$ #{program} jeos.appl -p vmware --platform-config type:personal,thin_disk:true # Build VMware image for VMware Server, Player, Fusion using thin (growing) disk
$ #{program} jeos.appl -p ec2 -d ami # Build and register AMI for jeos.appl
$ #{program} jeos.appl -p vmware -d local # Build VMware image for jeos.appl and deliver it to local directory
EOB
opts.separator ""
opts.separator "Options:"
opts.on("-p", "--platform [TYPE]", "The name of platform you want to convert to.") { |v| options.platform = v.to_sym }
opts.on("-d", "--delivery [METHOD]", "The delivery method for selected appliance.") { |v| options.delivery = v.to_sym }
opts.on("-f", "--force", "Force image creation - removes all previous builds for selected appliance. Default: false.") { |v| options.force = v }
opts.separator ""
opts.separator "Plugin configuration options:"
opts.on("-l", "--plugins [PLUGINS]", Array, "Comma separated list of additional plugins. Default: empty.") do |v|
options[:additional_plugins] = v
end
opts.separator ""
opts.on("--os-config [CONFIG]", Array, "Operating system plugin configuration in format: key1:value1,key2:value2.") do |v|
validate_hash_option(options, :os_config, v) do |entry|
puts "Operating system plugin configuration is not valid at '#{entry}'. Valid format is: 'key:value'."
end
end
opts.on("--platform-config [CONFIG]", Array, "Platform plugin configuration in format: key1:value1,key2:value2.") do |v|
validate_hash_option(options, :platform_config, v) do |entry|
puts "Platform plugin configuration is not valid at '#{entry}'. Valid format is: 'key:value'."
end
end
opts.on("--delivery-config [CONFIG]", Array, "Delivery plugin configuration in format: key1:value1,key2:value2.") do |v|
validate_hash_option(options, :delivery_config, v) do |entry|
puts "Delivery plugin configuration is not valid at '#{entry}'. Valid format is: 'key:value'."
end
end
opts.separator ""
opts.separator "Logging options:"
opts.on("--debug", "Prints debug information while building. Default: false.") { options[:log_level] = :debug }
opts.on("--trace", "Prints trace information while building. Default: false.") { options[:log_level] = :trace }
opts.on("-b", "--backtrace", "Prints full backtrace if errors occur whilst building. Default: true if console log is set to debug or trace, otherwise false.") { |v| options[:backtrace] = v }
opts.separator ""
opts.separator 'Common options:'
opts.on_tail('--help', 'Show this message.') do
puts opts
exit
end
opts.on_tail('--version', 'Print the version.') do
puts "BoxGrinder Build #{File.read("#{File.dirname(__FILE__)}/../CHANGELOG").match(/^v(.*)/)[1]}"
[:os, :platform, :delivery].each do |type|
puts
puts "Available #{type} plugins:"
BoxGrinder::PluginManager.instance.plugins[type].each do |name, plugin_info|
puts " - #{name} plugin for #{plugin_info[:full_name]}"
end
end
exit
end
opts.on('--change-to-user', 'Change from root to local user after the OS plugin completes.') do
options[:change_to_user] = true
end
end
end