/*
* Copyright (c) 2014 Villu Ruusmann
*
* This file is part of Openscoring
*
* Openscoring is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Openscoring is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Openscoring. If not, see <http://www.gnu.org/licenses/>.
*/
package org.openscoring.client;
import com.beust.jcommander.JCommander;
import com.beust.jcommander.Parameter;
import com.beust.jcommander.ParameterException;
abstract
public class Application {
@Parameter (
names = {"--help"},
description = "Show the list of configuration options and exit",
help = true
)
private boolean help = false;
abstract
public void run() throws Exception;
private boolean getHelp(){
return this.help;
}
static
public void run(Class<? extends Application> clazz, String... args) throws Exception {
Application application = clazz.newInstance();
JCommander commander = new JCommander(application);
commander.setProgramName(clazz.getName());
try {
commander.parse(args);
} catch(ParameterException pe){
commander.usage();
System.exit(-1);
}
if(application.getHelp()){
commander.usage();
System.exit(0);
}
application.run();
}
}