是否可以在JCommander中将带jcommander.Parameter
注释的类保存到文件中,这样就可以创建新对象,使用@ syntax从文件中读取?
例如,如果我有注释类
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;
}
和类初始化
IndexerCommandLineParameters p = new IndexerCommandLineParameters();
JCommander c=new JCommander(p);
c.parse("-s", "xxxxx","-d", "yyyyy");
p.verbositiy=2;
我想创建包含
之类的文件-s xxxxx -d yyyyy -v 3 -f
我知道我可以在每个类中创建.toString()
或类似内容,但我正在寻找更通用的内容,我不需要为每个带注释的类添加一些代码。