Added -h option to display available CLI options to user
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
Gregory Ballantine 2025-02-27 00:37:00 -05:00
parent 2a007df722
commit 5f8df35171

View File

@ -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);
CommandLineParser parser = new DefaultParser(); // allow the user to specify a config file manually
HelpFormatter formatter = new HelpFormatter(); Option configPath = new Option("c", "configPath", true, "Configuration file path (defaults to " + this.configPath + ")");
CommandLine cmd = parser.parse(options, args); configPath.setRequired(false);
options.addOption(configPath);
// set the configPath variable if the option was passed to the program CommandLineParser parser = new DefaultParser();
if (cmd.hasOption("configPath")) { CommandLine cmd = parser.parse(options, args);
this.configPath = cmd.getOptionValue("configPath");
} // 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");
}
}
public void printHelp(Options options) {
HelpFormatter formatter = new HelpFormatter();
formatter.printHelp("Dragoon", this.helpHeader, options, this.helpFooter, true);
System.exit(0);
} }
public String getConfigPath() { public String getConfigPath() {