Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
*.class
*.java~
*.java#
.*.swp
target
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
This is my own fork of the original https://github.com/arenn/java-getopt repository.

I have therefore added the following lines to the original README file

If you are using version 1.0.15 which includes the removal of System.err.println error
messages which are now replaced by throw new IllegalArgumentException therefore allowing
to use this library more easily in your code deciding on your own what you do with thrown
exceptions. You will also beneficiate from Maven build facility.

To build the jar type:
mvn clean ; mvn package

You an then use the jar produced under target/java-getopt-1.0.15.jar

The other changes I made are both cosmetic (code formating) and also try to comply
with some Java coding best practices like using "constant".compare(object_string) instead
of object_string.compare("constant") and isEmpty() rather than .length() == 0

Of course you can ask me to integrate any thing you see fit/missing and depending on
what my sparetime allows me I'll be more than happy to try to comply to your needs.
Feel free also to use

https://github.com/obourdon/java-getopt/issues

to log any issue you would like to be addressed

Thanks for everything

Olivier

olivier.bourdon@freesbee.fr

https://github.com/obourdon/java-getopt
4 changes: 4 additions & 0 deletions gnu/getopt/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
For release 1.0.15 (2015/01/07)

Olivier Bourdon (olivier.bourdon@freesbee.fr)

For release 1.0.14 (2012/02/08)

David Zhang (david290@qq.com) provided Chinese language messages.
Expand Down
Binary file removed gnu/getopt/Getopt.class
Binary file not shown.
2,301 changes: 1,083 additions & 1,218 deletions gnu/getopt/Getopt.java

Large diffs are not rendered by default.

Binary file removed gnu/getopt/GetoptDemo.class
Binary file not shown.
168 changes: 80 additions & 88 deletions gnu/getopt/GetoptDemo.java
Original file line number Diff line number Diff line change
@@ -1,97 +1,89 @@
import gnu.getopt.LongOpt;
import gnu.getopt.Getopt;
package gnu.getopt;

/*
* This sample code was written by Aaron M. Renn and is a demonstration
* of how to utilize some of the features of the GNU getopt package. This
* sample code is hereby placed into the public domain by the author and
* may be used without restriction.
*/
public class GetoptDemo {

public class GetoptDemo
{

public static void
main(String[] argv)
{
int c;
String arg;
LongOpt[] longopts = new LongOpt[3];
//
StringBuffer sb = new StringBuffer();
longopts[0] = new LongOpt("help", LongOpt.NO_ARGUMENT, null, 'h');
longopts[1] = new LongOpt("outputdir", LongOpt.REQUIRED_ARGUMENT, sb, 'o');
longopts[2] = new LongOpt("maximum", LongOpt.OPTIONAL_ARGUMENT, null, 2);
//
Getopt g = new Getopt("testprog", argv, "-:bc::d:hW;", longopts);
g.setOpterr(false); // We'll do our own error handling
//
while ((c = g.getopt()) != -1)
switch (c)
{
case 0:
arg = g.getOptarg();
System.out.println("Got long option with value '" +
(char)(new Integer(sb.toString())).intValue()
+ "' with argument " +
((arg != null) ? arg : "null"));
break;
//
case 1:
System.out.println("I see you have return in order set and that " +
"a non-option argv element was just found " +
"with the value '" + g.getOptarg() + "'");
break;
//
case 2:
arg = g.getOptarg();
System.out.println("I know this, but pretend I didn't");
System.out.println("We picked option " +
longopts[g.getLongind()].getName() +
" with value " +
((arg != null) ? arg : "null"));
break;
//
case 'b':
System.out.println("You picked plain old option " + (char)c);
break;
//
case 'c':
case 'd':
arg = g.getOptarg();
System.out.println("You picked option '" + (char)c +
"' with argument " +
((arg != null) ? arg : "null"));
break;
//
case 'h':
System.out.println("I see you asked for help");
break;
//
case 'W':
System.out.println("Hmmm. You tried a -W with an incorrect long " +
"option name");
break;
//
case ':':
System.out.println("Doh! You need an argument for option " +
(char)g.getOptopt());
break;
//
case '?':
System.out.println("The option '" + (char)g.getOptopt() +
"' is not valid");
break;
//
default:
System.out.println("getopt() returned " + c);
break;
}
//
for (int i = g.getOptind(); i < argv.length ; i++)
System.out.println("Non option argv element: " + argv[i] + "\n");
}

public static void main(String[] argv) {
int c;
String arg;
LongOpt[] longopts = new LongOpt[3];
//
StringBuffer sb = new StringBuffer();
longopts[0] = new LongOpt("help", LongOpt.NO_ARGUMENT, null, 'h');
longopts[1] = new LongOpt("outputdir", LongOpt.REQUIRED_ARGUMENT, sb, 'o');
longopts[2] = new LongOpt("maximum", LongOpt.OPTIONAL_ARGUMENT, null, 2);
//
Getopt g = new Getopt("testprog", argv, "-:bc::d:hW;", longopts);
g.setOpterr(false); // We'll do our own error handling
//
while ((c = g.getopt()) != -1) {
switch (c) {
case 0:
arg = g.getOptarg();
System.out.println("Got long option with value '" +
(char) (new Integer(sb.toString())).intValue() + "' with argument " +
((arg != null) ? arg : "null"));
break;
//
case 1:
System.out.println("I see you have return in order set and that " +
"a non-option argv element was just found " +
"with the value '" + g.getOptarg() + "'");
break;
//
case 2:
arg = g.getOptarg();
System.out.println("I know this, but pretend I didn't");
System.out.println("We picked option " +
longopts[g.getLongind()].getName() +
" with value " +
((arg != null) ? arg : "null"));
break;
//
case 'b':
System.out.println("You picked plain old option " + (char) c);
break;
//
case 'c':
case 'd':
arg = g.getOptarg();
System.out.println("You picked option '" + (char) c +
"' with argument " +
((arg != null) ? arg : "null"));
break;
//
case 'h':
System.out.println("I see you asked for help");
break;
//
case 'W':
System.out.println("Hmmm. You tried a -W with an incorrect long " +
"option name");
break;
//
case ':':
System.out.println("Doh! You need an argument for option " +
(char) g.getOptopt());
break;
//
case '?':
System.out.println("The option '" + (char) g.getOptopt() +
"' is not valid");
break;
//
default:
System.out.println("getopt() returned " + c);
break;
}
}
//
for (int i = g.getOptind(); i < argv.length; i++) {
System.out.println("Non option argv element: " + argv[i] + "\n");
}
}
} // Class GetoptDemo


Binary file removed gnu/getopt/LongOpt.class
Binary file not shown.
Loading