OptionSet options = parse(args);
String accessId = getAccessId(options);
String secretKey = getSecretKey(options);
String regionUrl = getRegionUrl(options);
Ec2Connection ec2Connection = new TypicaEc2Connection(accessId, secretKey, null, regionUrl);
List<String> hostNames = new ArrayList<String>();
File hostNamesFile = getInputFile(options, "hostnames");
File instancesFile = getInputFile(options, "instances");
if(hostNamesFile == null && instancesFile == null)
printUsage();
if(hostNamesFile != null) {
List<HostNamePair> hostNamePairs = getHostNamesPairsFromFile(hostNamesFile);
for(HostNamePair hostNamePair: hostNamePairs)
hostNames.add(hostNamePair.getExternalHostName());
ec2Connection.deleteInstancesByHostName(hostNames);
}
if(instancesFile != null) {
List<String> instanceIds = FileUtils.readLines(instancesFile);
ec2Connection.deleteInstancesByInstanceId(instanceIds);
}
}