[Issue #13] - adding install parameter to install a new config file
This commit is contained in:
parent
5f8df35171
commit
37f2bf0268
2
pom.xml
2
pom.xml
@ -182,7 +182,7 @@
|
|||||||
<packager>Bit Goblin</packager>
|
<packager>Bit Goblin</packager>
|
||||||
<prefix>/opt</prefix>
|
<prefix>/opt</prefix>
|
||||||
<changelogFile>${project.basedir}/src/build/changelog.txt</changelogFile>
|
<changelogFile>${project.basedir}/src/build/changelog.txt</changelogFile>
|
||||||
<targetOs>linux</targetOs>
|
<targetOs>${os.name}</targetOs>
|
||||||
<mappings>
|
<mappings>
|
||||||
<mapping>
|
<mapping>
|
||||||
<directory>/opt/dragoon</directory>
|
<directory>/opt/dragoon</directory>
|
||||||
|
@ -1,7 +1,16 @@
|
|||||||
package tech.bitgoblin.config;
|
package tech.bitgoblin.config;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Paths;
|
||||||
|
import java.nio.file.StandardCopyOption;
|
||||||
|
|
||||||
import org.apache.commons.cli.*;
|
import org.apache.commons.cli.*;
|
||||||
|
|
||||||
|
import tech.bitgoblin.Logger;
|
||||||
|
import tech.bitgoblin.io.IOUtils;
|
||||||
|
|
||||||
public class Cmd {
|
public class Cmd {
|
||||||
|
|
||||||
private String helpHeader = "Start the Dragoon video transcoder.";
|
private String helpHeader = "Start the Dragoon video transcoder.";
|
||||||
@ -16,6 +25,10 @@ public class Cmd {
|
|||||||
Option helpOption = new Option("h", "help", false, "Display CLI usage and options.");
|
Option helpOption = new Option("h", "help", false, "Display CLI usage and options.");
|
||||||
options.addOption(helpOption);
|
options.addOption(helpOption);
|
||||||
|
|
||||||
|
// install a config file in the user's home directory
|
||||||
|
Option installOption = new Option("i", "install", false, "Install configuration file in the user's home directory (or specify a location with -c).");
|
||||||
|
options.addOption(installOption);
|
||||||
|
|
||||||
// allow the user to specify a config file manually
|
// allow the user to specify a config file manually
|
||||||
Option configPath = new Option("c", "configPath", true, "Configuration file path (defaults to " + this.configPath + ")");
|
Option configPath = new Option("c", "configPath", true, "Configuration file path (defaults to " + this.configPath + ")");
|
||||||
configPath.setRequired(false);
|
configPath.setRequired(false);
|
||||||
@ -28,6 +41,17 @@ public class Cmd {
|
|||||||
if (cmd.hasOption("help")) {
|
if (cmd.hasOption("help")) {
|
||||||
this.printHelp(options);
|
this.printHelp(options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// check if the install option was called
|
||||||
|
if (cmd.hasOption("install")) {
|
||||||
|
try {
|
||||||
|
this.installConfig();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
Logger.logger.error("Unable to install new configuration file; please refer to the stack trace above to resolve the error.");
|
||||||
|
System.exit(2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// set the configPath variable if the option was passed to the program
|
// set the configPath variable if the option was passed to the program
|
||||||
if (cmd.hasOption("configPath")) {
|
if (cmd.hasOption("configPath")) {
|
||||||
@ -41,6 +65,15 @@ public class Cmd {
|
|||||||
|
|
||||||
System.exit(0);
|
System.exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void installConfig() throws IOException {
|
||||||
|
ClassLoader classloader = Thread.currentThread().getContextClassLoader();
|
||||||
|
InputStream is = classloader.getResourceAsStream("example.config");
|
||||||
|
Files.copy(is, Paths.get(IOUtils.resolveTilda(this.configPath)), StandardCopyOption.REPLACE_EXISTING);
|
||||||
|
Logger.logger.info("A new configuration file has been installed at " + this.configPath + ".");
|
||||||
|
|
||||||
|
System.exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
public String getConfigPath() {
|
public String getConfigPath() {
|
||||||
return this.configPath;
|
return this.configPath;
|
||||||
|
10
src/main/resources/example.config
Normal file
10
src/main/resources/example.config
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
[transcoder]
|
||||||
|
repo_path = '~/dragoon'
|
||||||
|
interval = 15
|
||||||
|
video_format = 'mov'
|
||||||
|
video_codec = 'dnxhd'
|
||||||
|
video_profile = 'dnxhr_hq'
|
||||||
|
video_resolution = '1920x1080'
|
||||||
|
video_framerate = '60'
|
||||||
|
video_color = 'yuv422p'
|
||||||
|
audio_codec = 'pcm_s16le'
|
Loading…
x
Reference in New Issue
Block a user