Author: [log in to unmask]
Date: Tue Mar 1 15:48:54 2016
New Revision: 4274
Log:
Use CSV output in print instead of space or tab delimited (compatible with load command now).
Modified:
java/trunk/conditions/src/main/java/org/hps/conditions/cli/PrintCommand.java
Modified: java/trunk/conditions/src/main/java/org/hps/conditions/cli/PrintCommand.java
=============================================================================
--- java/trunk/conditions/src/main/java/org/hps/conditions/cli/PrintCommand.java (original)
+++ java/trunk/conditions/src/main/java/org/hps/conditions/cli/PrintCommand.java Tue Mar 1 15:48:54 2016
@@ -40,16 +40,15 @@
static {
options.addOption(new Option("h", "help", false, "print help for print command"));
options.addOption(new Option("t", "table", true, "table name"));
- options.addOption(new Option("i", "print-id", false, "print the ID for the records (off by default)"));
- options.addOption(new Option("f", "file", true, "write print output to a file (must be used with -t option)"));
+ options.addOption(new Option("i", "print-id", false, "include the row IDs in printouts"));
+ options.addOption(new Option("f", "file", true, "write output to a file (requires -t option)"));
options.addOption(new Option("H", "no-header", false, "suppress printing of conditions record and table info"));
- options.addOption(new Option("d", "tabs", false, "use tabs for field delimiter instead of spaces"));
}
/**
* The field delimiter for print output.
*/
- private char fieldDelimiter = ' ';
+ private static final char DELIMITER = ',';
/**
* Output file if printing to a file.
@@ -125,11 +124,6 @@
// Print header info. Option turns this off.
if (commandLine.hasOption("h")) {
this.printHeaders = false;
- }
-
- // Use tabs instead of spaces for field delimiter.
- if (commandLine.hasOption("d")) {
- this.fieldDelimiter = '\t';
}
// List of conditions records to print.
@@ -173,7 +167,7 @@
for (final String columnName : collection.getTableMetaData().getFieldNames()) {
if (!"collection_id".equals(columnName)) {
buffer.append(((ConditionsObject) object).getFieldValue(columnName));
- buffer.append(this.fieldDelimiter);
+ buffer.append(DELIMITER);
}
}
buffer.setLength(buffer.length() - 1);
@@ -221,15 +215,17 @@
private void printColumnNames(final TableMetaData tableMetaData) {
if (this.printIDs) {
this.ps.print("id");
- this.ps.print(this.fieldDelimiter);
- }
+ this.ps.print(DELIMITER);
+ }
+ StringBuffer sb = new StringBuffer();
for (final String columnName : tableMetaData.getFieldNames()) {
if (!"collection_id".equals(columnName)) {
- this.ps.print(columnName);
- this.ps.print(this.fieldDelimiter);
- }
- }
- this.ps.println();
+ sb.append(columnName);
+ sb.append(DELIMITER);
+ }
+ }
+ sb.setLength(sb.length() - 1);
+ this.ps.println(sb.toString());
}
/**
|