| Path: | bin/boxgrinder-build |
| Last Update: | Fri Mar 11 10:18:43 +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 71
71: def process_options(options)
72: OptionParser.new do |opts|
73: program = File.basename($0)
74:
75: 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"
76:
77:
78: opts.separator ""
79: opts.separator "Options:"
80:
81: opts.on("-p", "--platform [TYPE]", "The name of platform you want to convert to.") { |v| options.platform = v.to_sym }
82: opts.on("-d", "--delivery [METHOD]", "The delivery method for selected appliance.") { |v| options.delivery = v.to_sym }
83: opts.on("-f", "--force", "Force image creation - removes all previous builds for selected appliance. Default: false.") { |v| options.force = v }
84:
85: opts.separator ""
86: opts.separator "Plugin configuration options:"
87:
88: opts.on("-l", "--plugins [PLUGINS]", Array, "Comma separated list of additional plugins. Default: empty.") do |v|
89: options[:additional_plugins] = v
90: end
91:
92: opts.separator ""
93:
94: opts.on("--os-config [CONFIG]", Array, "Operating system plugin configuration in format: key1:value1,key2:value2.") do |v|
95: validate_hash_option(options, :os_config, v) do |entry|
96: puts "Operating system plugin configuration is not valid at '#{entry}'. Valid format is: 'key:value'."
97: end
98: end
99:
100: opts.on("--platform-config [CONFIG]", Array, "Platform plugin configuration in format: key1:value1,key2:value2.") do |v|
101: validate_hash_option(options, :platform_config, v) do |entry|
102: puts "Platform plugin configuration is not valid at '#{entry}'. Valid format is: 'key:value'."
103: end
104: end
105:
106: opts.on("--delivery-config [CONFIG]", Array, "Delivery plugin configuration in format: key1:value1,key2:value2.") do |v|
107: validate_hash_option(options, :delivery_config, v) do |entry|
108: puts "Delivery plugin configuration is not valid at '#{entry}'. Valid format is: 'key:value'."
109: end
110: end
111:
112: opts.separator ""
113: opts.separator "Logging options:"
114:
115: opts.on("--debug", "Prints debug information while building. Default: false.") { |v| options[:debug] = v }
116: opts.on("--trace", "Prints trace information while building. Default: false.") { |v| options[:trace] = v }
117: 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 }
118:
119: opts.separator ""
120: opts.separator 'Common options:'
121:
122: opts.on_tail('--help', 'Show this message.') do
123: puts opts
124: exit
125: end
126: opts.on_tail('--version', 'Print the version.') do
127: puts "BoxGrinder Build #{File.read("#{File.dirname(__FILE__)}/../CHANGELOG").match(/^v(.*)/)[1]}"
128:
129: [:os, :platform, :delivery].each do |type|
130: puts
131: puts "Available #{type} plugins:"
132: BoxGrinder::PluginManager.instance.plugins[type].each do |name, plugin_info|
133: puts " - #{name} plugin for #{plugin_info[:full_name]}"
134: end
135: end
136:
137: exit
138: end
139: end
140: end
# File bin/boxgrinder-build, line 46
46: def validate_hash_option(options, name, value)
47: value.each do |entry|
48: if entry =~ /^(\S+):(\S+)$/
49:
50: k = $1.strip
51: v = $2.strip
52:
53: if v =~ /^([-+]?(0|[1-9][0-9_]*))$/
54: v = v.to_i
55: elsif v =~ /^(y|Y|yes|Yes|YES|true|True|TRUE|on|On|ON)$/
56: v = true
57: elsif v =~ /^(n|N|no|No|NO|false|False|FALSE|off|Off|OFF)$/
58: v = false
59: elsif v =~ /^([-+]?([0-9][0-9_]*)?\.[0-9.]*([eE][-+][0-9]+)?)$/
60: v = v.to_f
61: end
62:
63: options[name][k] = v
64: else
65: yield entry if block_given?
66: abort
67: end
68: end
69: end