1

Is it possible in JCommander to save class annotated with jcommander.Parameter to file, so one could create new object, using @ syntax to read from file?

For example, if I have annotated class

class IndexerCommandLineParameters {
    @Parameter(names = { "-s", "--source" }, description = "Source file or directory of audio files (*.wav or *.mp3). MUST BE 16bit!", required=true)
    public String source;

    @Parameter(names = { "-d", "--destination" }, description = "Destination file or directory (type must match source type).", required=true)
    public String destination;

    @Parameter(names = { "-v", "--verbositiy" }, description = "Verbosity in stderr: 0 - print only file processing errors, 1 - print indexing progress")
    public int verbositiy=1;

    @Parameter(names = {"-f", "--force"}, description = "Force to reindex alredy indexed fiels")
    public boolean reindex = true;

    @Parameter(names = {"-h", "--help"}, description = "Force to reindex alredy indexed fiels", help = true)
    private boolean help;
}

And class initialization

IndexerCommandLineParameters p = new IndexerCommandLineParameters();
JCommander c=new JCommander(p);
c.parse("-s", "xxxxx","-d", "yyyyy");
p.verbositiy=2;

I want to create file, that contains something like

-s xxxxx -d yyyyy -v 3 -f

I know I can create .toString() or something similar in each class, but I was looking for something more general, where I don't have to add some code to each annotated class.

Skriptotajs
  • 844
  • 6
  • 15

0 Answers0