-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve CLI arguments. Fix wrong regexes
- Loading branch information
1 parent
7c8be60
commit 7d06ff7
Showing
5 changed files
with
139 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
116 changes: 116 additions & 0 deletions
116
src/main/java/edu/wpi/first/wpilib/opencv/installer/MainCLI.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,116 @@ | ||
package edu.wpi.first.wpilib.opencv.installer; | ||
|
||
import edu.wpi.first.wpilib.opencv.installer.platform.Platform; | ||
import org.apache.commons.cli.CommandLine; | ||
import org.apache.commons.cli.CommandLineParser; | ||
import org.apache.commons.cli.DefaultParser; | ||
import org.apache.commons.cli.HelpFormatter; | ||
import org.apache.commons.cli.MissingOptionException; | ||
import org.apache.commons.cli.Option; | ||
import org.apache.commons.cli.Options; | ||
import org.apache.commons.cli.ParseException; | ||
|
||
import java.io.IOException; | ||
|
||
public class MainCLI { | ||
|
||
/** | ||
* Main entry point. | ||
*/ | ||
public static void main(String[] args) throws ParseException { | ||
CommandLineParser p = new DefaultParser(); | ||
Options options = new Options() {{ | ||
addOption(Option.builder("j") | ||
.longOpt("java") | ||
.optionalArg(true) | ||
.numberOfArgs(1) | ||
.argName("install-path") | ||
.desc("Install the OpenCV Java library") | ||
.build() | ||
); | ||
addOption(Option.builder("i") | ||
.longOpt("jni") | ||
.optionalArg(true) | ||
.numberOfArgs(1) | ||
.argName("install-path") | ||
.desc("Install the OpenCV JNI bindings") | ||
.build() | ||
); | ||
addOption(Option.builder("s") | ||
.longOpt("headers") | ||
.optionalArg(true) | ||
.numberOfArgs(1) | ||
.argName("install-path") | ||
.desc("Install the OpenCV C++ headers") | ||
.build() | ||
); | ||
addOption(Option.builder("n") | ||
.longOpt("natives") | ||
.optionalArg(true) | ||
.numberOfArgs(1) | ||
.argName("install-path") | ||
.desc("Install the OpenCV native libraries") | ||
.build() | ||
); | ||
addOption("h", "help", false, "Prints this help message"); | ||
addOption("a", "all", false, "Installs all artifacts"); | ||
addOption("v", "version", true, "Set the version of OpenCV to install"); | ||
addOption("o", "overwrite", false, "Overwrite existing files when installing"); | ||
addOption("p", "platform", true, "Install artifacts for a specific platform"); | ||
}}; | ||
|
||
// Parse CLI arguments | ||
CommandLine parsedArgs = p.parse(options, args); | ||
if (parsedArgs.hasOption("help")) { | ||
HelpFormatter hf = new HelpFormatter(); | ||
hf.printHelp("opencv-installer", options); | ||
return; | ||
} | ||
if (!parsedArgs.hasOption("version")) { | ||
throw new MissingOptionException("-v <version>"); | ||
} | ||
if (parsedArgs.hasOption("platform")) { | ||
Installer.setPlatform(Platform.valueOf(parsedArgs.getOptionValue("platform"))); | ||
} | ||
Platform platform = Installer.getPlatform(); | ||
Installer.setOpenCvVersion(parsedArgs.getOptionValue("version")); | ||
if (parsedArgs.hasOption("overwrite")) { | ||
Installer.overwriteExistingFiles(); | ||
} | ||
|
||
// Install selected artifacts | ||
System.out.println("Installing specified OpenCV components"); | ||
if (parsedArgs.hasOption("java") || parsedArgs.hasOption("all")) { | ||
try { | ||
Installer.installJava(parsedArgs.getOptionValue("java", platform.defaultJavaLocation())); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
if (parsedArgs.hasOption("jni") || parsedArgs.hasOption("all")) { | ||
try { | ||
Installer.installJni(parsedArgs.getOptionValue("jni", platform.defaultJniLocation())); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
if (parsedArgs.hasOption("headers") || parsedArgs.hasOption("all")) { | ||
try { | ||
Installer.installHeaders(parsedArgs.getOptionValue("headers", platform.defaultHeadersLocation())); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
if (parsedArgs.hasOption("natives") || parsedArgs.hasOption("all")) { | ||
try { | ||
Installer.installNatives(parsedArgs.getOptionValue("natives", platform.defaultNativesLocation())); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
System.out.println("=========================="); | ||
System.out.println("Finished installing OpenCV"); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters