Module: ParseArgs

Defined in:
lib/parse_args.rb

Class Method Summary collapse

Class Method Details

.get_vals_from_args(arg_list, all_flags, usage) ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/parse_args.rb', line 72

def self.get_vals_from_args(arg_list, all_flags, usage)
  val_hash = {}

  arg_hash = parse_argv(arg_list, all_flags, usage)

  if arg_hash['help'] || arg_hash['h'] || arg_hash['usage']
    raise BadCommandLineArgException.new(usage)
  end

  if arg_hash['version']
    raise BadCommandLineArgException.new(AS_VERSION)
  end

  self.get_min_and_max_images_and_ips(arg_hash, val_hash)

  if arg_hash['file']
    true_location = File.expand_path(arg_hash['file'])
    if !File.exists?(true_location)
      raise BadCommandLineArgException.new(NO_APP_FOUND)
    end

    if !((File.directory?(true_location)) or (true_location =~ TAR_REGEX))
      raise BadCommandLineArgException.new(FILE_FLAG_NOT_VALID_MSG) 
    end

    val_hash['file_location'] = arg_hash['file']
  else
    val_hash['file_location'] = nil
  end

  self.get_table_args(arg_hash, val_hash)
  self.get_cloud_args(arg_hash, val_hash)

  if arg_hash['keyname']
    val_hash['keyname'] = arg_hash['keyname']
  else
    val_hash['keyname'] = "appscale"
  end

  if arg_hash['appname']
    val_hash['appname'] = arg_hash['appname'].gsub(/[^\w\d-]/, "")
  else
    val_hash['appname'] = nil
  end

  # If the user tells us exactly how many application servers they want
  # per application, then don't use the autoscaling support.
  if arg_hash['appengine']
    val_hash['appengine'] = Integer(arg_hash['appengine'])
    val_hash['autoscale'] = false
  else
    val_hash['appengine'] = 1
    val_hash['autoscale'] = true
  end

  if arg_hash['separate']
    val_hash['separate'] = true
  else
    val_hash['separate'] = false
  end

  val_hash['confirm'] = !arg_hash['confirm'].nil?

  self.get_backup_and_restore_params(arg_hash, val_hash)
  self.get_developer_flags(arg_hash, val_hash)

  return val_hash
end