diff --git a/src/main/java/tech/bitgoblin/config/Cmd.java b/src/main/java/tech/bitgoblin/config/Cmd.java index fa306a8..e991164 100644 --- a/src/main/java/tech/bitgoblin/config/Cmd.java +++ b/src/main/java/tech/bitgoblin/config/Cmd.java @@ -4,23 +4,42 @@ import org.apache.commons.cli.*; 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"; public Cmd(String[] args) throws ParseException { Options options = new Options(); - Option configPath = new Option("c", "configPath", true, "configuration file path (defaults to /etc/dragoon/config.toml)"); - configPath.setRequired(false); - options.addOption(configPath); + // 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); + 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(); - HelpFormatter formatter = new HelpFormatter(); - CommandLine cmd = parser.parse(options, args); - - // 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() {