Created
April 17, 2019 00:17
-
-
Save luisenriquecorona/fa6a82ee8f63283d672d735ad15647ee to your computer and use it in GitHub Desktop.
Trivial demostration of GetOpt. If -h present, print help.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import com.darwinsys.util.GetOpt; | |
/** Trivial demonstration of GetOpt. If -h present, print help. | |
*/ | |
public class GetOptSimple { | |
public static void main(String[] args) { | |
GetOpt go = new GetOpt("h"); | |
char c; | |
while ((c = go.getopt(args)) !=GetOpt.DONE) { | |
switch(c) { | |
case 'h': | |
helpAndExit(0); | |
break; | |
default: | |
System.err.println("Unknown option in " + | |
args[go.getOptInd( )-1]); | |
helpAndExit(1); | |
} | |
} | |
System.out.println( ); | |
} | |
/** Stub for providing help on usage | |
* You can write a longer help than this, certainly. | |
*/ | |
static void helpAndExit(int returnValue) { | |
System.err.println("This would tell you how to use this program"); | |
System.exit(returnValue); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment