Thread: [Japi-cvs] SF.net SVN: japi: [193] libs/argparser/trunk/src/net/sf/japi/io/args/ BasicCommand.java
Status: Beta
Brought to you by:
christianhujer
From: <chr...@us...> - 2006-11-06 22:26:33
|
Revision: 193 http://svn.sourceforge.net/japi/?rev=193&view=rev Author: christianhujer Date: 2006-11-06 14:26:24 -0800 (Mon, 06 Nov 2006) Log Message: ----------- Added exit option to BasicCommand. Modified Paths: -------------- libs/argparser/trunk/src/net/sf/japi/io/args/BasicCommand.java Modified: libs/argparser/trunk/src/net/sf/japi/io/args/BasicCommand.java =================================================================== --- libs/argparser/trunk/src/net/sf/japi/io/args/BasicCommand.java 2006-10-30 10:57:59 UTC (rev 192) +++ libs/argparser/trunk/src/net/sf/japi/io/args/BasicCommand.java 2006-11-06 22:26:24 UTC (rev 193) @@ -1,13 +1,7 @@ package net.sf.japi.io.args; import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.Formatter; -import java.util.HashSet; -import java.util.List; -import java.util.MissingResourceException; -import java.util.ResourceBundle; -import java.util.Set; +import java.util.*; /** * BasicCommand is a base class for commands that provides the options --help and --version. @@ -21,6 +15,9 @@ /** The maximum width of the option type field. */ private final int maxOptionTypeWidth; + /** @see Command#isExiting() */ + private boolean exiting; + /** Create a BasicCommand. */ protected BasicCommand() { int tmpMaxOptionTypeWidth = 0; @@ -36,6 +33,23 @@ // TODO } + /** Exit Option. */ + @Option(names = {"exit"}) + public void setExiting() { + exiting = true; + } + + /** No Exit Option. */ + @Option(names = {"noexit"}) + public void setNotExiting() { + exiting = false; + } + + /** {@inheritDoc} */ + public boolean isExiting() { + return exiting; + } + /** Help Option. */ @Option(type = OptionType.TERMINAL, names = {"h", "help"}) public void help() { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2006-12-15 21:02:58
|
Revision: 262 http://svn.sourceforge.net/japi/?rev=262&view=rev Author: christianhujer Date: 2006-12-15 13:02:56 -0800 (Fri, 15 Dec 2006) Log Message: ----------- Fixed bugs: own resource bundle wasn't used, help header and footer were not used. Modified Paths: -------------- libs/argparser/trunk/src/net/sf/japi/io/args/BasicCommand.java Modified: libs/argparser/trunk/src/net/sf/japi/io/args/BasicCommand.java =================================================================== --- libs/argparser/trunk/src/net/sf/japi/io/args/BasicCommand.java 2006-12-15 21:01:10 UTC (rev 261) +++ libs/argparser/trunk/src/net/sf/japi/io/args/BasicCommand.java 2006-12-15 21:02:56 UTC (rev 262) @@ -81,6 +81,7 @@ } final String formatString = "%-" + maxShort + "s%s%-" + maxLong + "s: %s%s%n"; final Formatter format = new Formatter(System.err); + format.format(getHelpHeader()); for (final Method optionMethod : optionMethods) { final Option option = optionMethod.getAnnotation(Option.class); final OptionType optionType = option.type(); @@ -98,12 +99,13 @@ String description; try { final String optionKey = option.key().equals("") ? optionMethod.getName() : option.key(); - description = getBundle().getString(optionKey); + description = getString(optionKey); } catch (final MissingResourceException ignore) { description = ""; } format.format(formatString, StringJoiner.join(", ", shortNames), delim, StringJoiner.join(", ", longNames), description, optionType.getDescription()); } + format.format(getHelpFooter()); format.flush(); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2007-06-29 19:56:54
|
Revision: 458 http://svn.sourceforge.net/japi/?rev=458&view=rev Author: christianhujer Date: 2007-06-29 12:56:52 -0700 (Fri, 29 Jun 2007) Log Message: ----------- Fix for #1745284 --help options list is not sorted Modified Paths: -------------- libs/argparser/trunk/src/net/sf/japi/io/args/BasicCommand.java Modified: libs/argparser/trunk/src/net/sf/japi/io/args/BasicCommand.java =================================================================== --- libs/argparser/trunk/src/net/sf/japi/io/args/BasicCommand.java 2007-06-29 18:27:44 UTC (rev 457) +++ libs/argparser/trunk/src/net/sf/japi/io/args/BasicCommand.java 2007-06-29 19:56:52 UTC (rev 458) @@ -26,6 +26,9 @@ import java.util.MissingResourceException; import java.util.ResourceBundle; import java.util.Set; +import java.util.Map; +import java.util.HashMap; +import java.util.TreeSet; import org.jetbrains.annotations.NotNull; /** @@ -93,12 +96,12 @@ maxLong = Math.max(maxLong, currentLong - ", ".length()); maxShort = Math.max(maxShort, currentShort - ", ".length()); } - final String formatString = "%-" + maxShort + "s%s%-" + maxLong + "s: %s%s%n"; + final String formatString = "%s: %s%s%n"; final Formatter format = new Formatter(System.err); format.format(getHelpHeader()); + final Map<String, Method> methodMap = new HashMap<String, Method>(); for (final Method optionMethod : optionMethods) { final Option option = optionMethod.getAnnotation(Option.class); - final OptionType optionType = option.type(); final String[] names = option.value(); final List<String> shortNames = new ArrayList<String>(); final List<String> longNames = new ArrayList<String>(); @@ -110,6 +113,13 @@ } } final String delim = shortNames.size() > 0 && longNames.size() > 0 ? ", " : " "; + final String options = String.format("%-" + maxShort + "s%s%-" + maxLong + "s", StringJoiner.join(", ", shortNames), delim, StringJoiner.join(", ", longNames)); + methodMap.put(options, optionMethod); + } + for (final String options : new TreeSet<String>(methodMap.keySet())) { + final Method optionMethod = methodMap.get(options); + final Option option = optionMethod.getAnnotation(Option.class); + final OptionType optionType = option.type(); String description; try { final String optionKey = option.key().equals("") ? optionMethod.getName() : option.key(); @@ -117,7 +127,8 @@ } catch (final MissingResourceException ignore) { description = ""; } - format.format(formatString, StringJoiner.join(", ", shortNames), delim, StringJoiner.join(", ", longNames), description, optionType.getDescription()); + format.format(formatString, options, description, optionType.getDescription()); + } format.format(getHelpFooter()); format.flush(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2007-06-30 16:34:44
|
Revision: 479 http://svn.sourceforge.net/japi/?rev=479&view=rev Author: christianhujer Date: 2007-06-30 09:34:35 -0700 (Sat, 30 Jun 2007) Log Message: ----------- Sort option variants within an option. Modified Paths: -------------- libs/argparser/trunk/src/net/sf/japi/io/args/BasicCommand.java Modified: libs/argparser/trunk/src/net/sf/japi/io/args/BasicCommand.java =================================================================== --- libs/argparser/trunk/src/net/sf/japi/io/args/BasicCommand.java 2007-06-30 16:28:07 UTC (rev 478) +++ libs/argparser/trunk/src/net/sf/japi/io/args/BasicCommand.java 2007-06-30 16:34:35 UTC (rev 479) @@ -28,6 +28,7 @@ import java.util.Set; import java.util.SortedSet; import java.util.TreeSet; +import java.util.Collections; import org.jetbrains.annotations.NotNull; /** @@ -113,6 +114,8 @@ shortNames.add("-" + name); } } + Collections.sort(shortNames); + Collections.sort(longNames); final String delim = shortNames.size() > 0 && longNames.size() > 0 ? ", " : " "; String description; try { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <chr...@us...> - 2007-06-30 16:42:34
|
Revision: 480 http://svn.sourceforge.net/japi/?rev=480&view=rev Author: christianhujer Date: 2007-06-30 09:42:31 -0700 (Sat, 30 Jun 2007) Log Message: ----------- Added missing @NotNull / @Nullable annotations. Modified Paths: -------------- libs/argparser/trunk/src/net/sf/japi/io/args/BasicCommand.java Modified: libs/argparser/trunk/src/net/sf/japi/io/args/BasicCommand.java =================================================================== --- libs/argparser/trunk/src/net/sf/japi/io/args/BasicCommand.java 2007-06-30 16:34:35 UTC (rev 479) +++ libs/argparser/trunk/src/net/sf/japi/io/args/BasicCommand.java 2007-06-30 16:42:31 UTC (rev 480) @@ -71,7 +71,7 @@ * @see System#exit(int) * @see #setExiting(Boolean) */ - public Boolean isExiting() { + @NotNull public Boolean isExiting() { return exiting; } @@ -136,7 +136,7 @@ * That means overriding this method will not break any default behaviour of BasicCommand. * @return ResourceBundle for default locale. */ - public ResourceBundle getBundle() { + @NotNull public ResourceBundle getBundle() { return ownBundle; } @@ -146,7 +146,7 @@ * The default String for "helpHeader" is the empty String. * @return Help header. */ - public String getHelpHeader() { + @NotNull public String getHelpHeader() { return getString("helpHeader"); } @@ -156,7 +156,7 @@ * The default String for "helpFooter" is the empty String. * @return Help footer. */ - public String getHelpFooter() { + @NotNull public String getHelpFooter() { return getString("helpFooter"); } @@ -170,7 +170,7 @@ * @return String from the ResourceBundles. * @throws MissingResourceException In case all tries for retrieving a value for <var>key</var> failed. */ - private String getString(final String key) throws MissingResourceException { + @NotNull private String getString(@NotNull final String key) throws MissingResourceException { try { return getBundle().getString(key); } catch (final MissingResourceException e) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |