Skip to content

Commit 6a99918

Browse files
committed
revert CLI-166
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/cli/trunk@779646 13f79535-47bb-0310-9956-ffa450edef68
1 parent 0cebfb4 commit 6a99918

3 files changed

Lines changed: 0 additions & 102 deletions

File tree

src/java/org/apache/commons/cli/HelpFormatter.java

Lines changed: 0 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -136,11 +136,6 @@ public class HelpFormatter
136136
* Defaults to case-insensitive alphabetical sorting by option key
137137
*/
138138
protected Comparator optionComparator = new OptionComparator();
139-
140-
/**
141-
* Flag to determine if we try to determine terminal width
142-
*/
143-
private boolean autoWidth = false;
144139

145140
/**
146141
* Sets the 'width'.
@@ -331,28 +326,6 @@ public void setOptionComparator(Comparator comparator)
331326
}
332327
}
333328

334-
/**
335-
* Sets the 'autoWidth'.
336-
*
337-
* @param flag the new value of 'autoWidth'
338-
*/
339-
public void setAutoWidth(boolean flag)
340-
{
341-
this.autoWidth = flag;
342-
int newWidth = (flag ? getTerminalWidth() : DEFAULT_WIDTH);
343-
setWidth(newWidth);
344-
}
345-
346-
/**
347-
* Returns the 'autoWidth'.
348-
*
349-
* @return the 'autoWidth'
350-
*/
351-
public boolean getAutoWidth()
352-
{
353-
return autoWidth;
354-
}
355-
356329
/**
357330
* Print the help for <code>options</code> with the specified
358331
* command line syntax. This method prints help information to
@@ -662,58 +635,6 @@ private static void appendOption(final StringBuffer buff, final Option option, f
662635
buff.append("]");
663636
}
664637
}
665-
666-
/**
667-
* Returns the auto-detected Terminal width as reported by stty -a
668-
*
669-
*/
670-
671-
private static int getTerminalWidth()
672-
{
673-
int ret = DEFAULT_WIDTH;
674-
if (System.getProperty("os.name").toLowerCase().indexOf("windows") == -1) {
675-
String sttya = unixCmdOut("stty -a < /dev/tty");
676-
StringTokenizer stok = new StringTokenizer(sttya, ";");
677-
while (stok.hasMoreTokens()) {
678-
String out = stok.nextToken().trim();
679-
if (out.startsWith("columns")) {
680-
int index = out.lastIndexOf(" ");
681-
ret = Integer.parseInt(out.substring(index).trim());
682-
break;
683-
} else if (out.endsWith("columns")) {
684-
int index = out.indexOf(" ");
685-
ret = Integer.parseInt(out.substring(0, index).trim());
686-
break;
687-
}
688-
}
689-
}
690-
return ret;
691-
}
692-
693-
/**
694-
* Runs the provided Unix command line and returns stdout
695-
*
696-
* @param program the program to run
697-
*/
698-
private static String unixCmdOut(String program)
699-
{
700-
int c;
701-
InputStream in;
702-
String rstr;
703-
ByteArrayOutputStream sout = new ByteArrayOutputStream();
704-
try {
705-
Process p = Runtime.getRuntime().exec(new String[] {"/bin/sh","-c",program});
706-
in = p.getInputStream();
707-
while ((c = in.read()) != -1) {
708-
sout.write(c);
709-
}
710-
p.waitFor();
711-
rstr = new String(sout.toString());
712-
} catch (Exception e) {
713-
rstr = new String(DEFAULT_WIDTH + " columns;");
714-
}
715-
return rstr;
716-
}
717638

718639
/**
719640
* Print the cmdLineSyntax to the specified writer, using the

src/test/org/apache/commons/cli/HelpFormatterTest.java

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -450,22 +450,5 @@ public void testOptionWithoutShortFormat2()
450450
"footer"+EOL
451451
,out.toString());
452452
}
453-
454-
public void testAutoWidth()
455-
{
456-
// related to Bugzilla #19383 (CLI-67)
457-
Options options = new Options();
458-
options.addOption(new Option("a", "aaa", false, "aaaaaaa aaaa aaaaa aaaaaaaa aaaaaa aa aaaaa aaaaaaaaaaaaa"));
459-
options.addOption(new Option(null, "bbb", false, "bbbbbbb bbbb bbbbbb bbbbb bbbbbb bbbb bbbbbbbb bbbbbbbb bbbbbbbbbb"));
460-
options.addOption(new Option("c", null, false, "ccccccc ccccccccccc ccccccccccccc ccc ccccc cccccccc cccccccccccc ccccc ccc ccc ccccccccccccccccc cc"));
461-
462-
HelpFormatter formatter = new HelpFormatter();
463-
formatter.setAutoWidth(true);
464-
StringWriter out = new StringWriter();
465-
formatter.printHelp("foobar", options);
466-
assertEquals("1", "1");
467-
}
468-
469-
470453

471454
}

xdocs/changes.xml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,6 @@
2323
<body>
2424

2525
<release version="1.3" date="in SVN">
26-
<action type="add" dev="jim" issue="CLI-166">
27-
HelpFormatter can now autodetect (if desired) terminal width under Unix.
28-
This is done via setAutoWidth(true) and the actual terminal width determination
29-
is done internally by calling "/bin/sh -c stty -a < /dev/null". If anything
30-
fails, the defaultWidth is used.
31-
</action>
3226
<action type="add" dev="ebourg" issue="CLI-160">
3327
PosixParser now supports partial long options (--ver instead of --version)
3428
</action>

0 commit comments

Comments
 (0)