You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ji...@apache.org on 2009/05/28 18:22:05 UTC
svn commit: r779646 - in /commons/proper/cli/trunk:
src/java/org/apache/commons/cli/HelpFormatter.java
src/test/org/apache/commons/cli/HelpFormatterTest.java xdocs/changes.xml
Author: jim
Date: Thu May 28 16:22:05 2009
New Revision: 779646
URL: http://svn.apache.org/viewvc?rev=779646&view=rev
Log:
revert CLI-166
Modified:
commons/proper/cli/trunk/src/java/org/apache/commons/cli/HelpFormatter.java
commons/proper/cli/trunk/src/test/org/apache/commons/cli/HelpFormatterTest.java
commons/proper/cli/trunk/xdocs/changes.xml
Modified: commons/proper/cli/trunk/src/java/org/apache/commons/cli/HelpFormatter.java
URL: http://svn.apache.org/viewvc/commons/proper/cli/trunk/src/java/org/apache/commons/cli/HelpFormatter.java?rev=779646&r1=779645&r2=779646&view=diff
==============================================================================
--- commons/proper/cli/trunk/src/java/org/apache/commons/cli/HelpFormatter.java (original)
+++ commons/proper/cli/trunk/src/java/org/apache/commons/cli/HelpFormatter.java Thu May 28 16:22:05 2009
@@ -136,11 +136,6 @@
* Defaults to case-insensitive alphabetical sorting by option key
*/
protected Comparator optionComparator = new OptionComparator();
-
- /**
- * Flag to determine if we try to determine terminal width
- */
- private boolean autoWidth = false;
/**
* Sets the 'width'.
@@ -332,28 +327,6 @@
}
/**
- * Sets the 'autoWidth'.
- *
- * @param flag the new value of 'autoWidth'
- */
- public void setAutoWidth(boolean flag)
- {
- this.autoWidth = flag;
- int newWidth = (flag ? getTerminalWidth() : DEFAULT_WIDTH);
- setWidth(newWidth);
- }
-
- /**
- * Returns the 'autoWidth'.
- *
- * @return the 'autoWidth'
- */
- public boolean getAutoWidth()
- {
- return autoWidth;
- }
-
- /**
* Print the help for <code>options</code> with the specified
* command line syntax. This method prints help information to
* System.out.
@@ -662,58 +635,6 @@
buff.append("]");
}
}
-
- /**
- * Returns the auto-detected Terminal width as reported by stty -a
- *
- */
-
- private static int getTerminalWidth()
- {
- int ret = DEFAULT_WIDTH;
- if (System.getProperty("os.name").toLowerCase().indexOf("windows") == -1) {
- String sttya = unixCmdOut("stty -a < /dev/tty");
- StringTokenizer stok = new StringTokenizer(sttya, ";");
- while (stok.hasMoreTokens()) {
- String out = stok.nextToken().trim();
- if (out.startsWith("columns")) {
- int index = out.lastIndexOf(" ");
- ret = Integer.parseInt(out.substring(index).trim());
- break;
- } else if (out.endsWith("columns")) {
- int index = out.indexOf(" ");
- ret = Integer.parseInt(out.substring(0, index).trim());
- break;
- }
- }
- }
- return ret;
- }
-
- /**
- * Runs the provided Unix command line and returns stdout
- *
- * @param program the program to run
- */
- private static String unixCmdOut(String program)
- {
- int c;
- InputStream in;
- String rstr;
- ByteArrayOutputStream sout = new ByteArrayOutputStream();
- try {
- Process p = Runtime.getRuntime().exec(new String[] {"/bin/sh","-c",program});
- in = p.getInputStream();
- while ((c = in.read()) != -1) {
- sout.write(c);
- }
- p.waitFor();
- rstr = new String(sout.toString());
- } catch (Exception e) {
- rstr = new String(DEFAULT_WIDTH + " columns;");
- }
- return rstr;
- }
/**
* Print the cmdLineSyntax to the specified writer, using the
Modified: commons/proper/cli/trunk/src/test/org/apache/commons/cli/HelpFormatterTest.java
URL: http://svn.apache.org/viewvc/commons/proper/cli/trunk/src/test/org/apache/commons/cli/HelpFormatterTest.java?rev=779646&r1=779645&r2=779646&view=diff
==============================================================================
--- commons/proper/cli/trunk/src/test/org/apache/commons/cli/HelpFormatterTest.java (original)
+++ commons/proper/cli/trunk/src/test/org/apache/commons/cli/HelpFormatterTest.java Thu May 28 16:22:05 2009
@@ -450,22 +450,5 @@
"footer"+EOL
,out.toString());
}
-
- public void testAutoWidth()
- {
- // related to Bugzilla #19383 (CLI-67)
- Options options = new Options();
- options.addOption(new Option("a", "aaa", false, "aaaaaaa aaaa aaaaa aaaaaaaa aaaaaa aa aaaaa aaaaaaaaaaaaa"));
- options.addOption(new Option(null, "bbb", false, "bbbbbbb bbbb bbbbbb bbbbb bbbbbb bbbb bbbbbbbb bbbbbbbb bbbbbbbbbb"));
- options.addOption(new Option("c", null, false, "ccccccc ccccccccccc ccccccccccccc ccc ccccc cccccccc cccccccccccc ccccc ccc ccc ccccccccccccccccc cc"));
-
- HelpFormatter formatter = new HelpFormatter();
- formatter.setAutoWidth(true);
- StringWriter out = new StringWriter();
- formatter.printHelp("foobar", options);
- assertEquals("1", "1");
- }
-
-
}
Modified: commons/proper/cli/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/cli/trunk/xdocs/changes.xml?rev=779646&r1=779645&r2=779646&view=diff
==============================================================================
--- commons/proper/cli/trunk/xdocs/changes.xml (original)
+++ commons/proper/cli/trunk/xdocs/changes.xml Thu May 28 16:22:05 2009
@@ -23,12 +23,6 @@
<body>
<release version="1.3" date="in SVN">
- <action type="add" dev="jim" issue="CLI-166">
- HelpFormatter can now autodetect (if desired) terminal width under Unix.
- This is done via setAutoWidth(true) and the actual terminal width determination
- is done internally by calling "/bin/sh -c stty -a < /dev/null". If anything
- fails, the defaultWidth is used.
- </action>
<action type="add" dev="ebourg" issue="CLI-160">
PosixParser now supports partial long options (--ver instead of --version)
</action>