1
# Copyright 2008 Amazon.com, Inc. or its affiliates. All Rights
2
# Reserved. Licensed under the Amazon Software License (the
3
# "License"). You may not use this file except in compliance with the
4
# License. A copy of the License is located at
5
# http://aws.amazon.com/asl or in the "license" file accompanying this
6
# file. This file is distributed on an "AS IS" BASIS, WITHOUT
7
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See
8
# the License for the specific language governing permissions and
9
# limitations under the License.
12
require 'ec2/amitools/version'
14
class UnbundleParameters < OptionParser
16
MANIFEST_DESCRIPTION = "The path to the AMI manifest file."
17
USER_PK_PATH_DESCRIPTION= "The path to the user's PEM encoded private key."
18
SOURCE_DESCRIPTION = 'The directory containing bundled AMI parts to unbundle. Defaults to ".".'
19
DESTINATION_DESCRIPTION = 'The directory to unbundle the AMI into. Defaults to the ".".'
20
DEBUG_DESCRIPTION = "Print debug messages."
21
HELP_DESCRIPTION = "Display this help message and exit."
22
VERSION_DESCRIPTION = "Display the version and copyright notice and then exit."
24
attr_accessor :manifest,
31
class Error < RuntimeError
32
class MissingMandatory < Error
33
def initialize( name )
34
super( "missing mandatory parameter: #{name}" )
38
class InvalidValue < Error
39
def initialize( name, value )
40
super( "#{name} value invalid: #{value.to_s}" )
45
def initialize( argv, name )
48
self.banner = "Usage: #{name} PARAMETERS"
51
# Mandatory parameters.
54
separator( "MANDATORY PARAMETERS" )
56
on( '-m', '--manifest PATH', String, MANIFEST_DESCRIPTION ) do |manifest|
57
unless ( File::exist?( manifest ) and File::file?( manifest ) )
58
raise Error::InvalidValue.new( "--manifest", manifest )
63
on( '-k', '--privatekey PATH', String, USER_PK_PATH_DESCRIPTION ) do |p|
64
unless File:: exist?( p ) and File::file?( p )
65
raise Error::InvalidValue.new( '--privatekey', p )
71
# Optional parameters.
74
self.separator( "OPTIONAL PARAMETERS" )
76
on( '-s', '--source DIRECTORY', String, SOURCE_DESCRIPTION ) do |directory|
77
unless File::exist?( directory ) and File::directory?( directory )
78
raise Error::InvalidValue.new( '--source', directory )
83
on( '-d', '--destination DIRECTORY', String, DESTINATION_DESCRIPTION ) do |directory|
84
unless File::exist?( directory ) and File::directory?( directory )
85
raise Error::InvalidValue.new( '--destination', directory )
87
@destination = directory
90
on( '--debug', DEBUG_DESCRIPTION ) do
94
on( '-h', '--help', HELP_DESCRIPTION ) do
98
on( '--version', VERSION_DESCRIPTION ) do
99
puts version_copyright_string()
104
# Parse the command line parameters.
110
# Verify mandatory parameters.
112
raise Error::MissingMandatory.new( '--manifest' ) unless @manifest
113
raise Error::MissingMandatory.new( '--privatekey' ) unless @user_pk_path
116
# Set defaults for optional parameters.
118
@source = Dir::pwd() unless @source
119
@destination = Dir::pwd() unless @destination