-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
84 additions
and
13 deletions.
There are no files selected for viewing
97 changes: 84 additions & 13 deletions
97
spark-logo/src/main/java/org/sparklogo/project/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 |
---|---|---|
@@ -1,25 +1,96 @@ | ||
package org.sparklogo.project; | ||
|
||
import org.sparklogo.gui.Configuration; | ||
import picocli.CommandLine; | ||
import picocli.CommandLine.ArgGroup; | ||
import picocli.CommandLine.Parameters; | ||
import picocli.CommandLine.Command; | ||
import picocli.CommandLine.Option; | ||
|
||
import java.io.File; | ||
import java.util.concurrent.Callable; | ||
|
||
public class MainCLI { | ||
public static void main(String[] args) throws Exception { | ||
if (args.length != 1) { | ||
System.out.println("Usage: spark-logo path_to_project_file"); | ||
return; | ||
@Command(name = "spark-pl", version = "1.4.0", description = "A SPARK-PL command line tool") | ||
public class MainCLI implements Callable<Integer> { | ||
@Option(names = {"-h", "--help"}, usageHelp = true, description = "display this help message") | ||
@SuppressWarnings("unused") | ||
boolean usageHelpRequested; | ||
|
||
@Option(names = {"-v", "--version"}, versionHelp = true, description = "display version info") | ||
@SuppressWarnings("unused") | ||
boolean versionInfoRequested; | ||
|
||
@Option(names = {"-c", "--compile"}, description = "compile output Java files") | ||
boolean compileFlag; | ||
|
||
@Option(names = {"-o", "--output"}, description = "output directory") | ||
File outputDirectory; | ||
|
||
@Option(names = "--name", description = "custom project name") | ||
String projectName; | ||
|
||
@Option(names = "--lib", description = "path to SPARK/lib") | ||
File customLibPath; | ||
|
||
@ArgGroup(exclusive = true, multiplicity = "1") | ||
Exclusive groups; | ||
|
||
static class Exclusive { | ||
@ArgGroup(exclusive = false, multiplicity = "1") | ||
FileOptions fileOptions; | ||
|
||
@ArgGroup(exclusive = false, multiplicity = "1") | ||
ProjectOptions projectOptions; | ||
} | ||
|
||
static class ProjectOptions { | ||
@Option(names = {"-p", "--project"}, required = true, description = "compile the SPARK-PL project file") | ||
File projectFile; | ||
} | ||
|
||
static class FileOptions { | ||
@Parameters(arity = "1..*", description = "SPARK-PL files to compile") | ||
File[] inputFiles; | ||
} | ||
|
||
@Override | ||
public Integer call() throws Exception { | ||
Project project = getProject(); | ||
File libPath = getLibPath(); | ||
project.translate(libPath); | ||
if (compileFlag) { | ||
project.compile(libPath); | ||
} | ||
Project project = new Project(); | ||
Configuration config = new Configuration(); | ||
return 0; | ||
} | ||
|
||
System.out.println("Reading: " + args[0]); | ||
ProjectFile.readProjectFile(new File(args[0]), project); | ||
private Project getProject() throws Exception { | ||
final Project project = new Project(); | ||
if (groups.projectOptions != null) { | ||
ProjectFile.readProjectFile(groups.projectOptions.projectFile, project); | ||
} | ||
else { | ||
for (File file : groups.fileOptions.inputFiles) { | ||
project.addFile(file); | ||
} | ||
} | ||
if (outputDirectory != null){ | ||
project.setOutputDirectory(outputDirectory.getAbsoluteFile()); | ||
} | ||
if (projectName != null) { | ||
project.setName(projectName); | ||
} | ||
|
||
System.out.println("Translating"); | ||
project.translate(config.getLibPath()); | ||
return project; | ||
} | ||
|
||
private File getLibPath() { | ||
return customLibPath != null ? | ||
customLibPath : | ||
new Configuration().getLibPath(); | ||
} | ||
|
||
System.out.println("Compiling"); | ||
project.compile(config.getLibPath()); | ||
public static void main(String[] args) { | ||
System.exit(new CommandLine(new MainCLI()).execute(args)); | ||
} | ||
} |