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,25 +4,44 @@ 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
Option helpOption = new Option("h", "help", false, "Display CLI usage and options.");
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); configPath.setRequired(false);
options.addOption(configPath); options.addOption(configPath);
CommandLineParser parser = new DefaultParser(); CommandLineParser parser = new DefaultParser();
HelpFormatter formatter = new HelpFormatter();
CommandLine cmd = parser.parse(options, args); 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 // set the configPath variable if the option was passed to the program
if (cmd.hasOption("configPath")) { if (cmd.hasOption("configPath")) {
this.configPath = cmd.getOptionValue("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() {
return this.configPath; return this.configPath;
} }