-
-
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.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
1 changed file
with
57 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,20 +27,73 @@ | |
*/ | ||
package com.manorrock.sphynx.cli; | ||
|
||
import java.io.File; | ||
import static java.lang.System.Logger.Level.INFO; | ||
import java.util.ArrayList; | ||
import java.util.concurrent.Callable; | ||
import picocli.CommandLine; | ||
|
||
/** | ||
* The execute command. | ||
* | ||
* | ||
* @author Manfred Riem ([email protected]) | ||
*/ | ||
@CommandLine.Command(name = "execute", mixinStandardHelpOptions = true) | ||
public class ExecuteCommand implements Callable<Integer> { | ||
public class ExecuteCommand implements Callable<Integer> { | ||
|
||
/** | ||
* Stores the logger. | ||
*/ | ||
private static final System.Logger LOGGER = System.getLogger(ExecuteCommand.class.getName()); | ||
|
||
/** | ||
* Stores the base directory. | ||
*/ | ||
@CommandLine.Option(names = "--base-directory", description = "The base directory used for storage") | ||
protected File baseDirectory = new File(System.getProperty("user.home") + "/.manorrock/sphynx"); | ||
|
||
/** | ||
* Stores the name. | ||
*/ | ||
@CommandLine.Option(names = "--name", description = "The name of the job", required = true) | ||
protected String name; | ||
|
||
@Override | ||
public Integer call() throws Exception { | ||
System.out.println("TODO - execute job"); | ||
return 0; | ||
/* | ||
* Step 1 - Determine job directory. | ||
*/ | ||
File jobDirectory = new File(baseDirectory, "jobs" + File.separator + name); | ||
|
||
/* | ||
* Step 2 - Determine script filename. | ||
*/ | ||
File scriptFilename = new File(jobDirectory, "script" + File.separator + "run.sh"); | ||
if (System.getProperty("os.name").toLowerCase().contains("windows")) { | ||
scriptFilename = new File(jobDirectory, "script" + File.separator + "run.cmd"); | ||
} | ||
|
||
/** | ||
* Step 4 - Create command array. | ||
*/ | ||
ArrayList<String> commands = new ArrayList<>(); | ||
commands.add("sh"); | ||
commands.add(scriptFilename.getAbsolutePath()); | ||
|
||
/** | ||
* Step 5 - Determine work directory. | ||
*/ | ||
File workDirectory = new File(jobDirectory, "work"); | ||
|
||
/* | ||
* Step 3 - Create process. | ||
*/ | ||
Process process = new ProcessBuilder() | ||
.command(commands) | ||
.directory(workDirectory) | ||
.inheritIO() | ||
.start(); | ||
|
||
return process.waitFor(); | ||
} | ||
} |