Using usage() after parsing my parameters.

30 views
Skip to first unread message

Szymon Tosik

unread,
Jul 16, 2017, 8:52:30 AM7/16/17
to jcommander
Hey I'm wondering how could I use usage() method after probably all constructors which supported that have been deprecated. I'm doing as follows :

public class App {


 
@Parameter
 
private List<String> parameters = new ArrayList<>();


 
@Parameter(names = {"-log", "-verbose"}, description = "Level of verbosity")
 
private Integer verbose = 1;


 
@Parameter(names = {"-t", "-type"}, description = "Type of file (file = f), (directory = d)")
 
private String type;


 
@Parameter(names = {"-e", "-ext"}, description = "Extension of files to be filtered")
 
private String extension;


 
@Parameter(names = "-wc", description = "Processor to be used during processing results")
 
private String processor;
 
 
@Parameter(names = "--help", help = true)
 
private boolean help = false;


 
public static void main(String[] args) throws FileNotFoundException, URISyntaxException {


   
App main = new App();
   
JCommander.newBuilder()
             
.addObject(main)
             
.build()
             
.parse(args);
   
   
if(main.help) {
   
// display usage  
   
}
 
}
}


Hopefully there is some efficient way after parsing parameters to do so. Thanks for any help as I didn't find how to do so in documentation.

Cédric Beust ♔

unread,
Jul 16, 2017, 9:06:50 AM7/16/17
to jcommander

How about

    JCommander jc = JCommander.newBuilder()
              .addObject(main)
              .build();

    jc.parse(args);

    if(main.help) {
      jc.usage();
    }
-- 
Cédric


--
You received this message because you are subscribed to the Google Groups "jcommander" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jcommander+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages