Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[HHQ-3275] Add --properties option to CLI commands to override defaul…

…t location for user.home/.hq/client.properties
  • Loading branch information...
commit ca7c9bce65f69aed1ef71e7ceb80976cc6e4980b 1 parent fd54742
Ryan Morgan authored
Showing with 25 additions and 5 deletions.
  1. +3 −0  ChangeLog
  2. +22 −5 src/org/hyperic/hq/hqapi1/tools/Command.java
View
3  ChangeLog
@@ -1,6 +1,9 @@
Changes in HQApi 3.0
+ *) [HHQ-3275] Add --properties option to CLI commands to override default
+ location for user.home/.hq/client.properties
+
*) [HHQ-3216] Implement MetricDataApi.addData()
*) [HHQ-3216] Revamp metricData CLI command to allow metrics to be pulled
View
27 src/org/hyperic/hq/hqapi1/tools/Command.java
@@ -50,6 +50,7 @@
static final String[] OPT_SECURE = {"s", "secure"};
static final String[] OPT_HELP = {"h","help"};
static final String OPT_FILE = "file";
+ static final String OPT_PROPERTIES = "properties";
// Ripped out from PluginMain.java
private static final String[][] LOG_PROPS = {
@@ -97,6 +98,10 @@ static OptionParser getOptionParser() {
"not specified, stdin will be used.").
withRequiredArg().ofType(String.class);
+ parser.accepts(OPT_PROPERTIES, "Specify the file to read for connection " +
+ "properties. Defaults to ~/.hq/client.properties")
+ .withRequiredArg().ofType(String.class);
+
return parser;
}
@@ -111,12 +116,23 @@ protected OptionSet getOptions(OptionParser p, String[] args) throws IOException
return o;
}
- private Properties getClientProperties() {
+ private Properties getClientProperties(String file) {
Properties props = new Properties();
- String home = System.getProperty("user.home");
- File hq = new File(home, ".hq");
- File clientProperties = new File(hq, "client.properties");
+ File clientProperties;
+
+ if (file != null) {
+ clientProperties = new File(file);
+ if (!clientProperties.exists()) {
+ System.err.println("Error: " + clientProperties.toString() +
+ " does not exist");
+ System.exit(-1);
+ }
+ } else {
+ String home = System.getProperty("user.home");
+ File hq = new File(home, ".hq");
+ clientProperties = new File(hq, "client.properties");
+ }
if (clientProperties.exists()) {
props = new Properties();
@@ -144,7 +160,8 @@ protected InputStream getInputStream(OptionSet s) throws Exception {
protected HQApi getApi(OptionSet s) {
- Properties clientProps = getClientProperties();
+ Properties clientProps =
+ getClientProperties((String)s.valueOf(OPT_PROPERTIES));
String host = (String)s.valueOf(OPT_HOST);
if (host == null) {
Please sign in to comment.
Something went wrong with that request. Please try again.