class ParametersBase

Constants

BATCH_DESCRIPTION
DEBUG_DESCRIPTION
HELP_DESCRIPTION
MANUAL_DESCRIPTION
PASS_DESCRIPTION
USER_ACCOUNT_DESCRIPTION
USER_CERT_PATH_DESCRIPTION

Descriptions for common parameters:

USER_DESCRIPTION
USER_PK_PATH_DESCRIPTION
VERSION_DESCRIPTION

Attributes

batch_mode[RW]
debug[RW]
manual[RW]
show_help[RW]
version[RW]

Public Class Methods

new(argv, name=nil) click to toggle source
Calls superclass method
# File lib/ec2/amitools/parameters_base.rb, line 146
def initialize(argv, name=nil)
  super(argv)

  # Mandatory parameters.
  separator("")
  separator("MANDATORY PARAMETERS")
  mandatory_params()
  
  # Optional parameters.
  separator("")
  separator("OPTIONAL PARAMETERS")
  common_params()
  optional_params()

  # Parse the command line parameters.
  parse!(argv)

  unless early_exit?
    validate_params()
    set_defaults()
  end
end

Public Instance Methods

assert_directory_exists(path, param) click to toggle source
# File lib/ec2/amitools/parameters_base.rb, line 101
def assert_directory_exists(path, param)
  unless (File::exist?(path) and File::directory?(path))
    raise InvalidValue.new(param, path, "Directory does not exist or is not a directory.")
  end
end
assert_exists(path, param) click to toggle source
# File lib/ec2/amitools/parameters_base.rb, line 77
def assert_exists(path, param)
  unless File::exist?(path)
    raise InvalidValue.new(param, path, "File or directory does not exist.")
  end
end
assert_file_executable(path, param) click to toggle source
# File lib/ec2/amitools/parameters_base.rb, line 95
def assert_file_executable(path, param)
  unless (File::executable?(path) and File::file?(path))
    raise InvalidValue.new(param, path, "File not executable.")
  end
end
assert_file_exists(path, param) click to toggle source
# File lib/ec2/amitools/parameters_base.rb, line 89
def assert_file_exists(path, param)
  unless (File::exist?(path) and File::file?(path))
    raise InvalidValue.new(param, path, "File does not exist or is not a file.")
  end
end
assert_glob_expands(path, param) click to toggle source
# File lib/ec2/amitools/parameters_base.rb, line 83
def assert_glob_expands(path, param)
  if Dir::glob(path).empty?
    raise InvalidValue.new(param, path, "File or directory does not exist.")
  end
end
assert_good_key(key, param) click to toggle source
# File lib/ec2/amitools/parameters_base.rb, line 113
def assert_good_key(key, param)
  if key.include?("/")
    raise InvalidValue.new(param, key, "'/' character not allowed.")
  end
end
assert_option_in(option, choices, param) click to toggle source
# File lib/ec2/amitools/parameters_base.rb, line 107
def assert_option_in(option, choices, param)
  unless choices.include?(option)
    raise InvalidValue.new(param, option)
  end
end
common_params() click to toggle source
# File lib/ec2/amitools/parameters_base.rb, line 123
def common_params()
  on('-h', '--help', HELP_DESCRIPTION) do
    @show_help = true
  end
  
  on('--version', VERSION_DESCRIPTION) do
    @version = true
  end
  
  on('--manual', MANUAL_DESCRIPTION) do
    @manual = true
  end
  
  on('--batch', BATCH_DESCRIPTION) do
    @batch_mode = true
  end
  
  on('--debug', DEBUG_DESCRIPTION) do
    @debug = true
  end    
end
early_exit?() click to toggle source
# File lib/ec2/amitools/parameters_base.rb, line 61
def early_exit?()
  @show_help or @manual or @version
end
interactive?() click to toggle source
# File lib/ec2/amitools/parameters_base.rb, line 65
def interactive?()
  not (early_exit? or @batch_mode)
end
mandatory_params() click to toggle source
# File lib/ec2/amitools/parameters_base.rb, line 41
def mandatory_params()
  # Override this for mandatory parameters
end
optional_params() click to toggle source
# File lib/ec2/amitools/parameters_base.rb, line 45
def optional_params()
  # Override this for optional parameters
end
set_defaults() click to toggle source
# File lib/ec2/amitools/parameters_base.rb, line 53
def set_defaults()
  # Override this for parameter validation
end
validate_params() click to toggle source
# File lib/ec2/amitools/parameters_base.rb, line 49
def validate_params()
  # Override this for parameter validation
end