Skip to content
Snippets Groups Projects
Commit 3c3cdc01 authored by Martin Vogel's avatar Martin Vogel
Browse files

refactor(cmd-runner): load default config from same path as client jar if present

parent 4ce40afb
No related branches found
No related tags found
No related merge requests found
......@@ -6,7 +6,7 @@ The sdk comes with a commandline client to be able to use the sdk without any co
#### Setup & Build
1. Build project root wih ``./mvnw clean package``
2. Go to client/target and find a runnable jar ``client-VERSION.jar``
3. Provide [config yaml](../config.yml) either via env-var or by loading it programmatically:
3. Provide [config yaml](../config.yml):
1. set environment variable ``FIT_CONNECT_CONFIG``:
1. Linux/MacOS: ``export FIT_CONNECT_CONFIG=path/to/config.yml``
2. Windows: ``set FIT_CONNECT_CONFIG=C:\Path\To\config.yml``
......@@ -15,6 +15,7 @@ The sdk comes with a commandline client to be able to use the sdk without any co
var config = ApplicationConfigLoader.loadConfig("absolute/path/to/config.yml");
var senderClient = ClientFactory.senderClient(config);
````
3. put ``config.yml`` in same path as the .jar-file
5. run client with ``java -jar client-VERSION.jar [COMMAND] [OPTIONS]``
#### SEND Example
......
package dev.fitko.fitconnect.client.cmd;
import dev.fitko.fitconnect.api.config.ApplicationConfig;
import dev.fitko.fitconnect.client.SenderClient;
import dev.fitko.fitconnect.client.SubscriberClient;
import dev.fitko.fitconnect.client.factory.ApplicationConfigLoader;
import dev.fitko.fitconnect.client.factory.ClientFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
......@@ -13,6 +17,7 @@ import java.util.stream.Collectors;
public final class CommandLineRunner {
private static final String LOGO = "/splash_screen_banner.txt";
public static final String DEFAULT_CONFIG_NAME = "config.yml";
private static final Logger LOGGER = LoggerFactory.getLogger(CommandLineRunner.class);
......@@ -24,16 +29,25 @@ public final class CommandLineRunner {
run(args);
}
private static void printSplashScreen() {
LOGGER.info("{}", getSplashScreenResource(LOGO));
}
private static void run(final String[] args) throws IOException {
final var senderClient = ClientFactory.senderClient();
final var subscriberClient = ClientFactory.subscriberClient();
final ApplicationConfig config = ApplicationConfigLoader.loadConfig(DEFAULT_CONFIG_NAME);
final var senderClient = getSenderClient(config);
final var subscriberClient = getSubscriberClient(config);
new CommandLineClient(senderClient, subscriberClient).run(args);
}
private static SubscriberClient.RequestSubmission getSubscriberClient(final ApplicationConfig config) {
return config != null ? ClientFactory.subscriberClient(config) : ClientFactory.subscriberClient();
}
private static SenderClient.Start getSenderClient(final ApplicationConfig config) {
return config != null ? ClientFactory.senderClient(config) : ClientFactory.senderClient();
}
private static void printSplashScreen() {
LOGGER.info("{}", getSplashScreenResource(LOGO));
}
private static String getSplashScreenResource(final String bannerName) {
final InputStream is = CommandLineRunner.class.getResourceAsStream(bannerName);
return new BufferedReader(new InputStreamReader(is)).lines().collect(Collectors.joining("\n"));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment