From d9b2b9b7578edb367174b1a516f38feb6eb028ae Mon Sep 17 00:00:00 2001
From: neil_a_wilson <neil_a_wilson@localhost>
Date: Fri, 10 Nov 2006 23:45:06 +0000
Subject: [PATCH] Make a number of changes to administrative tools provided with OpenDS. These are all made under the umbrella of issue #994, but there are individual issues for each change.
---
opends/src/server/org/opends/server/util/args/SubCommandArgumentParser.java | 80 ++++++++++++++++++++++++++++++---------
1 files changed, 61 insertions(+), 19 deletions(-)
diff --git a/opends/src/server/org/opends/server/util/args/SubCommandArgumentParser.java b/opends/src/server/org/opends/server/util/args/SubCommandArgumentParser.java
index c008de1..76bb8ec 100644
--- a/opends/src/server/org/opends/server/util/args/SubCommandArgumentParser.java
+++ b/opends/src/server/org/opends/server/util/args/SubCommandArgumentParser.java
@@ -88,6 +88,10 @@
// the program with which this argument parser is associated.
private String mainClassName;
+ // A human-readable description for the tool, which will be included when
+ // displaying usage information.
+ private String toolDescription;
+
// The raw set of command-line arguments that were provided.
private String[] rawArguments;
@@ -104,14 +108,18 @@
* class that should be invoked to launch
* the program with which this argument
* parser is associated.
+ * @param toolDescription A human-readable description for the
+ * tool, which will be included when
+ * displaying usage information.
* @param longArgumentsCaseSensitive Indicates whether subcommand and long
* argument names should be treated in a
* case-sensitive manner.
*/
- public SubCommandArgumentParser(String mainClassName,
+ public SubCommandArgumentParser(String mainClassName, String toolDescription,
boolean longArgumentsCaseSensitive)
{
this.mainClassName = mainClassName;
+ this.toolDescription = toolDescription;
this.longArgumentsCaseSensitive = longArgumentsCaseSensitive;
globalArgumentList = new LinkedList<Argument>();
@@ -143,6 +151,20 @@
/**
+ * Retrieves a human-readable description for this tool, which should be
+ * included at the top of the command-line usage information.
+ *
+ * @return A human-readable description for this tool, or {@code null} if
+ * none is available.
+ */
+ public String getToolDescription()
+ {
+ return toolDescription;
+ }
+
+
+
+ /**
* Indicates whether subcommand names and long argument strings should be
* treated in a case-sensitive manner.
*
@@ -1050,8 +1072,24 @@
*/
public void getFullUsage(StringBuilder buffer)
{
- buffer.append("Usage: java ");
- buffer.append(mainClassName);
+ if ((toolDescription != null) && (toolDescription.length() > 0))
+ {
+ buffer.append(wrapText(toolDescription, 79));
+ buffer.append(EOL);
+ }
+
+ String scriptName = System.getProperty(PROPERTY_SCRIPT_NAME);
+ if ((scriptName == null) || (scriptName.length() == 0))
+ {
+ buffer.append("Usage: java ");
+ buffer.append(mainClassName);
+ }
+ else
+ {
+ buffer.append("Usage: ");
+ buffer.append(scriptName);
+ }
+
buffer.append(" {subcommand} {options}");
buffer.append(EOL);
buffer.append(EOL);
@@ -1109,8 +1147,6 @@
buffer.append(value);
}
}
-
- buffer.append(EOL);
}
buffer.append(EOL);
@@ -1175,8 +1211,6 @@
buffer.append(EOL);
}
-
- buffer.append(EOL);
}
}
@@ -1193,8 +1227,18 @@
*/
public void getSubCommandUsage(StringBuilder buffer, SubCommand subCommand)
{
- buffer.append("Usage: java ");
- buffer.append(mainClassName);
+ String scriptName = System.getProperty(PROPERTY_SCRIPT_NAME);
+ if ((scriptName == null) || (scriptName.length() == 0))
+ {
+ buffer.append("Usage: java ");
+ buffer.append(mainClassName);
+ }
+ else
+ {
+ buffer.append("Usage: ");
+ buffer.append(scriptName);
+ }
+
buffer.append(" ");
buffer.append(subCommand.getName());
buffer.append(" {options}");
@@ -1262,21 +1306,21 @@
// indent the description five characters and try our best to wrap at or
// before column 79 so it will be friendly to 80-column displays.
String description = a.getDescription();
- if (description.length() <= 74)
+ if (description.length() <= 75)
{
- buffer.append(" ");
+ buffer.append(" ");
buffer.append(description);
buffer.append(EOL);
}
else
{
String s = description;
- while (s.length() > 74)
+ while (s.length() > 75)
{
- int spacePos = s.lastIndexOf(' ', 74);
+ int spacePos = s.lastIndexOf(' ', 75);
if (spacePos > 0)
{
- buffer.append(" ");
+ buffer.append(" ");
buffer.append(s.substring(0, spacePos).trim());
s = s.substring(spacePos+1).trim();
buffer.append(EOL);
@@ -1289,14 +1333,14 @@
spacePos = s.indexOf(' ');
if (spacePos > 0)
{
- buffer.append(" ");
+ buffer.append(" ");
buffer.append(s.substring(0, spacePos).trim());
s = s.substring(spacePos+1).trim();
buffer.append(EOL);
}
else
{
- buffer.append(" ");
+ buffer.append(" ");
buffer.append(s);
s = "";
buffer.append(EOL);
@@ -1306,7 +1350,7 @@
if (s.length() > 0)
{
- buffer.append(" ");
+ buffer.append(" ");
buffer.append(s);
buffer.append(EOL);
}
@@ -1441,8 +1485,6 @@
buffer.append(EOL);
}
}
-
- buffer.append(EOL);
}
}
--
Gitblit v1.10.0