110 lines
2.9 KiB
Java
110 lines
2.9 KiB
Java
package eu.dnetlib.broker;
|
|
|
|
import java.io.PrintWriter;
|
|
import java.util.Arrays;
|
|
|
|
import org.apache.commons.cli.CommandLine;
|
|
import org.apache.commons.cli.CommandLineParser;
|
|
import org.apache.commons.cli.DefaultParser;
|
|
import org.apache.commons.cli.HelpFormatter;
|
|
import org.apache.commons.cli.Option;
|
|
import org.apache.commons.cli.Options;
|
|
import org.apache.commons.cli.ParseException;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.boot.CommandLineRunner;
|
|
import org.springframework.boot.SpringApplication;
|
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
|
|
|
@SpringBootApplication
|
|
public class BrokerClientApp implements CommandLineRunner {
|
|
|
|
private static Logger log = LoggerFactory.getLogger(BrokerClientApp.class);
|
|
|
|
@Value("${dhp.broker.api.base-url}")
|
|
private String defaultBrokerApiBaseUrl;
|
|
|
|
public static void main(final String[] args) {
|
|
SpringApplication.run(BrokerClientApp.class, args);
|
|
}
|
|
|
|
@Override
|
|
public void run(final String... args) {
|
|
log.info("EXECUTING : command line runner");
|
|
|
|
final Options options = new Options();
|
|
|
|
options.addOption(Option.builder("v")
|
|
.required(false)
|
|
.hasArg(false)
|
|
.desc("verbose")
|
|
.build());
|
|
|
|
options.addOption(Option.builder("u")
|
|
.required(true)
|
|
.hasArg(true)
|
|
.longOpt("user")
|
|
.desc("the email of the subscriber")
|
|
.build());
|
|
|
|
options.addOption(Option.builder("bu")
|
|
.required(false)
|
|
.hasArg(true)
|
|
.longOpt("baseurl")
|
|
.desc("the broker public api baseUrl")
|
|
.build());
|
|
|
|
options.addOption(Option.builder("o")
|
|
.required(true)
|
|
.hasArg(true)
|
|
.longOpt("output")
|
|
.desc("the output dir")
|
|
.build());
|
|
|
|
try {
|
|
|
|
final CommandLineParser parser = new DefaultParser();
|
|
|
|
final CommandLine cmd = parser.parse(options, args);
|
|
|
|
if (cmd.hasOption("v")) {
|
|
|
|
}
|
|
|
|
final String user = cmd.getOptionValue("u");
|
|
final String baseUrl = cmd.getOptionValue("bu", defaultBrokerApiBaseUrl);
|
|
final String outputDir = cmd.getOptionValue("o");
|
|
|
|
log.info("USER: " + user);
|
|
log.info("BASE_URL: " + baseUrl);
|
|
log.info("OUPUT DIR: " + outputDir);
|
|
|
|
} catch (final ParseException e) {
|
|
System.err.println("\nERROR: Unable to parse command-line arguments " + Arrays.toString(args) + " due to: " + e);
|
|
printHelp(options);
|
|
}
|
|
}
|
|
|
|
private void printHelp(final Options options) {
|
|
final HelpFormatter formatter = new HelpFormatter();
|
|
|
|
final String syntax = "Main";
|
|
System.out.println("\n=====");
|
|
System.out.println("USAGE");
|
|
System.out.println("=====");
|
|
final PrintWriter pw = new PrintWriter(System.out);
|
|
formatter.printUsage(pw, 80, syntax, options);
|
|
pw.flush();
|
|
|
|
final String usageHeader = "OpenAIRE Broker - Public API Client\n";
|
|
final String usageFooter = "\nSee http://.../... for further details.";
|
|
System.out.println("\n====");
|
|
System.out.println("HELP");
|
|
System.out.println("====");
|
|
|
|
formatter.printHelp(syntax, options);
|
|
System.out.println();
|
|
}
|
|
}
|