Added -h option to display available CLI options to user
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
This commit is contained in:
parent
2a007df722
commit
5f8df35171
@ -4,23 +4,42 @@ import org.apache.commons.cli.*;
|
|||||||
|
|
||||||
public class Cmd {
|
public class Cmd {
|
||||||
|
|
||||||
|
private String helpHeader = "Start the Dragoon video transcoder.";
|
||||||
|
private String helpFooter = "Report issues at https://git.metaunix.net/BitGoblin/dragoon/issues/";
|
||||||
|
|
||||||
private String configPath = "~/.config/dragoon.toml";
|
private String configPath = "~/.config/dragoon.toml";
|
||||||
|
|
||||||
public Cmd(String[] args) throws ParseException {
|
public Cmd(String[] args) throws ParseException {
|
||||||
Options options = new Options();
|
Options options = new Options();
|
||||||
|
|
||||||
Option configPath = new Option("c", "configPath", true, "configuration file path (defaults to /etc/dragoon/config.toml)");
|
// print help for the user
|
||||||
configPath.setRequired(false);
|
Option helpOption = new Option("h", "help", false, "Display CLI usage and options.");
|
||||||
options.addOption(configPath);
|
options.addOption(helpOption);
|
||||||
|
|
||||||
|
// allow the user to specify a config file manually
|
||||||
|
Option configPath = new Option("c", "configPath", true, "Configuration file path (defaults to " + this.configPath + ")");
|
||||||
|
configPath.setRequired(false);
|
||||||
|
options.addOption(configPath);
|
||||||
|
|
||||||
|
CommandLineParser parser = new DefaultParser();
|
||||||
|
CommandLine cmd = parser.parse(options, args);
|
||||||
|
|
||||||
|
// check if the help option was called
|
||||||
|
if (cmd.hasOption("help")) {
|
||||||
|
this.printHelp(options);
|
||||||
|
}
|
||||||
|
|
||||||
|
// set the configPath variable if the option was passed to the program
|
||||||
|
if (cmd.hasOption("configPath")) {
|
||||||
|
this.configPath = cmd.getOptionValue("configPath");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
CommandLineParser parser = new DefaultParser();
|
public void printHelp(Options options) {
|
||||||
HelpFormatter formatter = new HelpFormatter();
|
HelpFormatter formatter = new HelpFormatter();
|
||||||
CommandLine cmd = parser.parse(options, args);
|
formatter.printHelp("Dragoon", this.helpHeader, options, this.helpFooter, true);
|
||||||
|
|
||||||
// set the configPath variable if the option was passed to the program
|
System.exit(0);
|
||||||
if (cmd.hasOption("configPath")) {
|
|
||||||
this.configPath = cmd.getOptionValue("configPath");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getConfigPath() {
|
public String getConfigPath() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user