Skip to content

Commit

Permalink
Added option to load config
Browse files Browse the repository at this point in the history
  • Loading branch information
dashrath-chauhan committed Nov 18, 2024
1 parent 0191c77 commit b5bd3ee
Showing 1 changed file with 24 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.ga4gh.starterkit.drs.app;

import org.apache.catalina.connector.Connector;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.*;
import org.ga4gh.starterkit.common.config.DatabaseProps;
import org.ga4gh.starterkit.common.config.ServerProps;
import org.ga4gh.starterkit.common.hibernate.HibernateEntity;
Expand Down Expand Up @@ -118,6 +118,25 @@ public DrsServerYamlConfigContainer defaultDrsConfigContainer() {
return new DrsServerYamlConfigContainer(new DrsServerYamlConfig());
}

public static boolean validateArguments(ApplicationArguments args, String optionName) {
try {
Options options = new Options();
options.addOption(Option.builder("c")
.longOpt(optionName)
.hasArg()
.desc("Path to configuration file")
.required()
.build());

CommandLineParser parser = new DefaultParser();
parser.parse(options, args.getSourceArgs());
return true;
} catch (ParseException e) {
System.out.println("ERROR: Invalid arguments: " + e.getMessage());
return false;
}
}

/**
* Loads a DRS config container singleton containing user-specified properties (via config file)
* @param args command line args
Expand All @@ -132,6 +151,10 @@ public DrsServerYamlConfigContainer runtimeDrsConfigContainer(
@Autowired() Options options,
@Qualifier(DrsServerConstants.EMPTY_DRS_CONFIG_CONTAINER) DrsServerYamlConfigContainer drsConfigContainer
) {
if (!validateArguments(args, "config")) {
System.exit(1); // Exit if validation fails
}

DrsServerYamlConfigContainer userConfigContainer = CliYamlConfigLoader.load(DrsServerYamlConfigContainer.class, args, options, "config");
if (userConfigContainer != null) {
return userConfigContainer;
Expand Down

0 comments on commit b5bd3ee

Please sign in to comment.