-
Notifications
You must be signed in to change notification settings - Fork 188
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix deprecation in SampleMain.java #147
base: master
Are you sure you want to change the base?
Conversation
Displays usage of all of the methods showed in the previous sample.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for re-pull-requesting, @KarlFish
Looks already quite good.
I have two small suggestions for you.
return; | ||
} | ||
|
||
if( arguments.isEmpty() ) | ||
System.out.println("No args given. Example useage: java SampleMain" + parser.printExample(OptionHandlerFilter.ALL)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should probably go to System.err
, as goes e.printStackTrace()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removing the help message on parsing error was a mistake, thanks for correcting that.
The second change depends on whether the program should run given no arguments. However, programs that use args4j will likely require some arguments to run correctly. I agree with this change as well.
System.err.println(" Example: java SampleMain"+parser.printExample(ALL)); | ||
|
||
} catch (CmdLineException e) { | ||
e.printStackTrace(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The printing of the help message in case of a CmdLineException
(malformed CLI options) is completely lost which was a good example in my humble opinion:
System.err.println(e.getMessage());
System.err.println("java SampleMain [options...] arguments...");
// print the list of available options
parser.printUsage(System.err);
System.err.println();
Removing the help message on parsing error was a mistake, thanks for correcting that. The second change depends on whether the program should run given no arguments. However, programs that use args4j will likely require some arguments to run correctly. I agree with this change as well. |
Thanks for fixing the deprecations! |
@sfuhrm , this is the updated version of my previous pull request. I had to create a new one because I deleted the repository I used.
I removed
CmdLineException
and matched the formatting ofargument.isEmpty()
to the other if statements.