diff --git a/wildfirestorage-cli/src/main/java/com/sjsu/wildfirestorage/Main.java b/wildfirestorage-cli/src/main/java/com/sjsu/wildfirestorage/Main.java index fa9b69d..e750e1c 100644 --- a/wildfirestorage-cli/src/main/java/com/sjsu/wildfirestorage/Main.java +++ b/wildfirestorage-cli/src/main/java/com/sjsu/wildfirestorage/Main.java @@ -1,7 +1,9 @@ package com.sjsu.wildfirestorage; + import org.springframework.core.ParameterizedTypeReference; import org.springframework.util.LinkedMultiValueMap; import org.springframework.web.reactive.function.client.WebClient; +import org.springframework.web.reactive.function.client.WebClientException; import picocli.CommandLine; import java.nio.file.Files; @@ -23,24 +25,35 @@ static class Cli { public void datasetInfo(@CommandLine.Parameters(paramLabel = "fileName") String fileName, @CommandLine.Parameters(paramLabel = "hostname") String hostname) throws InterruptedException { System.out.println("GET returned: " + Client.get(Client.getWebClient(hostname + "/api/metadata"), new LinkedMultiValueMap(Map.of("filename", List.of(fileName))), - new ParameterizedTypeReference>(){})); + new ParameterizedTypeReference>() { + })); } @CommandLine.Command - public void share(@CommandLine.Option(description = "Absolute file name", names = "--file", required = true) String fileName, - @CommandLine.Parameters(paramLabel = "hostname") String hostname, - @CommandLine.Option(names = "--token") String token) throws InterruptedException, ExecutionException { - System.out.println("POST returned: " + Client.post(Client.getWebClient(hostname + "/api/share-link/create"), - fileName.replace("\"", ""), - new ParameterizedTypeReference(){}, httpHeaders -> { - httpHeaders.setBearerAuth(token); - })); + public void share(@CommandLine.Option(names = "--meta-url", description = "URL of metadata server", defaultValue = "http://127.0.0.1:27777") String metaURL, + @CommandLine.Parameters(description = "Absolute file name", index = "0..*") String[] fileNames, + @CommandLine.Option(names = "--token", required = true) String token) throws InterruptedException, ExecutionException { + for (var fileName : fileNames) { + try { + System.out.println(Client.post(Client.getWebClient(metaURL + "/api/share-link/create"), + fileName, + new ParameterizedTypeReference() { + }, httpHeaders -> { + httpHeaders.setBearerAuth(token); + })); + } catch (ExecutionException e) { + var message = e.getMessage(); + // if this is a message about a connection problem, drop all the text before connection + if (message.contains("Connection")) message = message.substring(message.indexOf("Connection")); + System.err.printf("%s: %s\n", message, fileName); + } + } } @CommandLine.Command public void search(@CommandLine.Parameters(paramLabel = "query") String query, @CommandLine.Parameters(paramLabel = "hostname") String hostname, @CommandLine.Parameters(paramLabel = "