new LongOpt("enable", LongOpt.NO_ARGUMENT, null, 'e'), // enable agent updates
new LongOpt("download", LongOpt.NO_ARGUMENT, null, 'o'), // downloads the agent update binary
new LongOpt("status", LongOpt.NO_ARGUMENT, null, 's') // status as to whether its enabled/disabled
};
Getopt getopt = new Getopt(getPromptCommandString(), args, sopts, lopts);
int code;
while ((code = getopt.getopt()) != -1) {
switch (code) {
case ':':
case '?':
case 1: {
out.println(MSG.getMsg(AgentI18NResourceKeys.HELP_SYNTAX_LABEL, getSyntax()));
break;
}
case 'u': {
// this method outputs messages to the user; it also will not return if successful
AgentUpdateThread.updateAgentNow(agent, true);
break;
}
case 'v': {
URL url = null;
try {
AgentUpdateVersion check = new AgentUpdateVersion(agent);
url = check.getVersionUrl();
AgentUpdateInformation info = check.getAgentUpdateInformation();
out.println(MSG.getMsg(AgentI18NResourceKeys.UPDATE_CHECK_INFO, url, info.getUpdateVersion(), info
.getUpdateBuild(), info.getAgentVersion(), info.getAgentBuild()));
if (info.isAgentOutOfDate()) {
out.println(MSG.getMsg(AgentI18NResourceKeys.UPDATE_CHECK_OOD));
} else {
if (info.isAgentOutOfDateStrict()) {
out.println(MSG.getMsg(AgentI18NResourceKeys.UPDATE_CHECK_OOD_STRICT));
} else {
out.println(MSG.getMsg(AgentI18NResourceKeys.UPDATE_CHECK_NOT_OOD));
}
}
} catch (Exception e) {
out.println(MSG.getMsg(AgentI18NResourceKeys.UPDATE_CHECK_FAILED, url, e));
}
break;
}
case 'd': {
Preferences prefs = agent.getConfiguration().getPreferences();
String prefName = AgentConfigurationConstants.AGENT_UPDATE_ENABLED;
boolean prefValue = false;
prefs.putBoolean(prefName, prefValue);
try {
prefs.flush();
} catch (BackingStoreException e) {
out.println(MSG.getMsg(AgentI18NResourceKeys.CANNOT_STORE_PREFERENCES, prefName, prefValue));
}
out.println(MSG.getMsg(AgentI18NResourceKeys.UPDATE_DISABLED));
break;
}
case 'e': {
Preferences prefs = agent.getConfiguration().getPreferences();
String prefName = AgentConfigurationConstants.AGENT_UPDATE_ENABLED;
boolean prefValue = true;
prefs.putBoolean(prefName, prefValue);
try {
prefs.flush();
} catch (BackingStoreException e) {
out.println(MSG.getMsg(AgentI18NResourceKeys.CANNOT_STORE_PREFERENCES, prefName, prefValue));
}
out.println(MSG.getMsg(AgentI18NResourceKeys.UPDATE_ENABLED));
break;
}
case 'o': {
try {
AgentUpdateDownload aud = new AgentUpdateDownload(agent);
aud.download();
aud.validate();
out.println(MSG.getMsg(AgentI18NResourceKeys.UPDATE_DOWNLOADED, aud.getAgentUpdateBinaryFile()));
} catch (Exception e) {
out.println(MSG.getMsg(AgentI18NResourceKeys.UPDATE_DOWNLOAD_FAILED, ThrowableUtil
.getAllMessages(e)));
}
break;
}
case 's': {
if (agent.getConfiguration().isAgentUpdateEnabled()) {
out.println(MSG.getMsg(AgentI18NResourceKeys.UPDATE_ENABLED));
} else {
out.println(MSG.getMsg(AgentI18NResourceKeys.UPDATE_DISABLED));
}
break;
}
}
}
if ((getopt.getOptind() + 1) < args.length) {
out.println(MSG.getMsg(AgentI18NResourceKeys.HELP_SYNTAX_LABEL, getSyntax()));
}
return;
}