Add simple argument parsing

This commit is contained in:
manzerbredes 2016-03-28 14:43:24 +02:00
parent 8b5387b882
commit 276d7a0874
2 changed files with 56 additions and 0 deletions

Binary file not shown.

56
src/app/App.java Normal file
View file

@ -0,0 +1,56 @@
package org.manzerbredes.open_klm.app;
import org.kohsuke.args4j.CmdLineException;
import org.kohsuke.args4j.CmdLineParser;
import org.kohsuke.args4j.Option;
import org.manzerbredes.open_klm.client.MainWindow;
import org.manzerbredes.open_klm.drivers.*;
import org.manzerbredes.open_klm.drivers.DriverTypeA;
import org.manzerbredes.open_klm.drivers.DriverTypeA.*;
/**
* Hello world!
*
*/
public class App
{
@Option(name="-leftColor",usage="Set the left color")
public String leftColor=null;
@Option(name="-middleColor",usage="Set the middle color")
public String middleColor=null;
@Option(name="-rightColor",usage="Set the right color")
public String rightColor=null;
public void parseArguments(){
if(this.leftColor!=null || this.rightColor!=null || this.middleColor!=null){
try {
DriverTypeA device=new Device_1770_ff00();
if(this.leftColor==null)
this.leftColor="OFF";
if(this.middleColor==null)
this.middleColor="OFF";
if(this.rightColor==null)
this.rightColor="OFF";
device.setRegionColor(Region.LEFT, Color.valueOf(leftColor), Intensity.HIGH);
device.setRegionColor(Region.MIDDLE, Color.valueOf(middleColor), Intensity.HIGH);
device.setRegionColor(Region.RIGHT, Color.valueOf(rightColor), Intensity.HIGH);
} catch (InstantiationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.exit(0);
}
}
public static void main( String[] args ) throws InstantiationException, CmdLineException
{
App app =new App();
CmdLineParser parser = new CmdLineParser(app);
parser.parseArgument(args);
app.parseArguments();
new MainWindow();
}
}