From: <otm...@us...> - 2008-10-16 21:21:13
|
Revision: 5448 http://jython.svn.sourceforge.net/jython/?rev=5448&view=rev Author: otmarhumbel Date: 2008-10-16 21:21:08 +0000 (Thu, 16 Oct 2008) Log Message: ----------- added prescan of arguments Modified Paths: -------------- trunk/installer/src/java/org/python/util/install/InstallerCommandLine.java trunk/installer/test/java/org/python/util/install/InstallerCommandLineTest.java Modified: trunk/installer/src/java/org/python/util/install/InstallerCommandLine.java =================================================================== --- trunk/installer/src/java/org/python/util/install/InstallerCommandLine.java 2008-10-16 21:15:59 UTC (rev 5447) +++ trunk/installer/src/java/org/python/util/install/InstallerCommandLine.java 2008-10-16 21:21:08 UTC (rev 5448) @@ -30,8 +30,8 @@ private static final String SILENT_LONG = "silent"; private static final String SILENT_DESC = "silent installation (without user interaction)"; - private static final String VERBOSE_SHORT = "v"; - private static final String VERBOSE_LONG = "verbose"; + protected static final String VERBOSE_SHORT = "v"; + protected static final String VERBOSE_LONG = "verbose"; private static final String VERBOSE_DESC = "print more output during the installation\n" + "(also valid in GUI and autotest mode)"; @@ -123,6 +123,22 @@ } /** + * Pre-scan of the arguments to detect a verbose flag + * @param args + * @return <code>true</code> if there is a verbose option + */ + public static final boolean hasVerboseOptionInArgs(String[] args) { + String shortVerbose = "-".concat(VERBOSE_SHORT); + String longVerbose = "--".concat(VERBOSE_LONG); + for (String arg : args) { + if (shortVerbose.equals(arg) || longVerbose.equals(arg)) { + return true; + } + } + return false; + } + + /** * constructor intended for JUnit tests only. */ public InstallerCommandLine() { Modified: trunk/installer/test/java/org/python/util/install/InstallerCommandLineTest.java =================================================================== --- trunk/installer/test/java/org/python/util/install/InstallerCommandLineTest.java 2008-10-16 21:15:59 UTC (rev 5447) +++ trunk/installer/test/java/org/python/util/install/InstallerCommandLineTest.java 2008-10-16 21:21:08 UTC (rev 5448) @@ -511,4 +511,27 @@ commandLine.printHelp(); } + public void testHasVerboseOptionInArgs() { + String[] args = new String[0]; + assertFalse(InstallerCommandLine.hasVerboseOptionInArgs(args)); + + args = new String[] {"a", "b", "c"}; + assertFalse(InstallerCommandLine.hasVerboseOptionInArgs(args)); + + args = new String[] {"a", InstallerCommandLine.VERBOSE_SHORT, "c"}; + assertFalse(InstallerCommandLine.hasVerboseOptionInArgs(args)); + + args = new String[] {"a", "-" + InstallerCommandLine.VERBOSE_SHORT, "c"}; + assertTrue(InstallerCommandLine.hasVerboseOptionInArgs(args)); + + args = new String[] {"a", InstallerCommandLine.VERBOSE_LONG, "c"}; + assertFalse(InstallerCommandLine.hasVerboseOptionInArgs(args)); + + args = new String[] {"a", "-" + InstallerCommandLine.VERBOSE_LONG, "c"}; + assertFalse(InstallerCommandLine.hasVerboseOptionInArgs(args)); + + args = new String[] {"a", "--" + InstallerCommandLine.VERBOSE_LONG, "c"}; + assertTrue(InstallerCommandLine.hasVerboseOptionInArgs(args)); + } + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |