Path: | bin/boxgrinder-build |
Last Update: | Wed Apr 27 16:37:28 +0000 2011 |
Copyright 2010 Red Hat, Inc.
This is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.
This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along with this software; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA, or see the FSF site: www.fsf.org.
# File bin/boxgrinder-build, line 66 66: def process_options(options) 67: OptionParser.new do |opts| 68: program = File.basename($0) 69: 70: opts.banner = "Usage: \#{program} [appliance definition file] [options]\n\nA tool for building VM images from simple definition files.\n \nHomepage:\n http://boxgrinder.org/\n\nDocumentation:\n http://boxgrinder.org/tutorials/\n\nExamples:\n $ \#{program} jeos.appl # Build KVM image for jeos.appl\n $ \#{program} jeos.appl -f # Build KVM image for jeos.appl with removing previous build for this image\n $ \#{program} jeos.appl --os-config format:qcow2 # Build KVM image for jeos.appl with a qcow2 disk\n $ \#{program} jeos.appl -p vmware --platform-config type:personal,thin_disk:true # Build VMware image for VMware Server, Player, Fusion using thin (growing) disk\n $ \#{program} jeos.appl -p ec2 -d ami # Build and register AMI for jeos.appl\n $ \#{program} jeos.appl -p vmware -d local # Build VMware image for jeos.appl and deliver it to local directory\n" 71: 72: 73: opts.separator "" 74: opts.separator "Options:" 75: 76: opts.on("-p", "--platform [TYPE]", "The name of platform you want to convert to.") { |v| options.platform = v.to_sym } 77: opts.on("-d", "--delivery [METHOD]", "The delivery method for selected appliance.") { |v| options.delivery = v.to_sym } 78: opts.on("-f", "--force", "Force image creation - removes all previous builds for selected appliance. Default: false.") { |v| options.force = v } 79: 80: opts.separator "" 81: opts.separator "Plugin configuration options:" 82: 83: opts.on("-l", "--plugins [PLUGINS]", Array, "Comma separated list of additional plugins. Default: empty.") do |v| 84: options[:additional_plugins] = v 85: end 86: 87: opts.separator "" 88: 89: opts.on("--os-config [CONFIG]", Array, "Operating system plugin configuration in format: key1:value1,key2:value2.") do |v| 90: validate_hash_option(options, :os_config, v) do |entry| 91: puts "Operating system plugin configuration is not valid at '#{entry}'. Valid format is: 'key:value'." 92: end 93: end 94: 95: opts.on("--platform-config [CONFIG]", Array, "Platform plugin configuration in format: key1:value1,key2:value2.") do |v| 96: validate_hash_option(options, :platform_config, v) do |entry| 97: puts "Platform plugin configuration is not valid at '#{entry}'. Valid format is: 'key:value'." 98: end 99: end 100: 101: opts.on("--delivery-config [CONFIG]", Array, "Delivery plugin configuration in format: key1:value1,key2:value2.") do |v| 102: validate_hash_option(options, :delivery_config, v) do |entry| 103: puts "Delivery plugin configuration is not valid at '#{entry}'. Valid format is: 'key:value'." 104: end 105: end 106: 107: opts.separator "" 108: opts.separator "Logging options:" 109: 110: opts.on("--debug", "Prints debug information while building. Default: false.") { options[:log_level] = :debug } 111: opts.on("--trace", "Prints trace information while building. Default: false.") { options[:log_level] = :trace } 112: 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 } 113: 114: opts.separator "" 115: opts.separator 'Common options:' 116: 117: opts.on_tail('--help', 'Show this message.') do 118: puts opts 119: exit 120: end 121: opts.on_tail('--version', 'Print the version.') do 122: puts "BoxGrinder Build #{File.read("#{File.dirname(__FILE__)}/../CHANGELOG").match(/^v(.*)/)[1]}" 123: 124: [:os, :platform, :delivery].each do |type| 125: puts 126: puts "Available #{type} plugins:" 127: BoxGrinder::PluginManager.instance.plugins[type].each do |name, plugin_info| 128: puts " - #{name} plugin for #{plugin_info[:full_name]}" 129: end 130: end 131: 132: exit 133: end 134: end 135: end
# File bin/boxgrinder-build, line 41 41: def validate_hash_option(options, name, value) 42: value.each do |entry| 43: if entry =~ /^(\S+):(\S+)$/ 44: 45: k = $1.strip 46: v = $2.strip 47: 48: if v =~ /^([-+]?(0|[1-9][0-9_]*))$/ 49: v = v.to_i 50: elsif v =~ /^(y|Y|yes|Yes|YES|true|True|TRUE|on|On|ON)$/ 51: v = true 52: elsif v =~ /^(n|N|no|No|NO|false|False|FALSE|off|Off|OFF)$/ 53: v = false 54: elsif v =~ /^([-+]?([0-9][0-9_]*)?\.[0-9.]*([eE][-+][0-9]+)?)$/ 55: v = v.to_f 56: end 57: 58: options[name][k] = v 59: else 60: yield entry if block_given? 61: abort 62: end 63: end 64: end