-
Notifications
You must be signed in to change notification settings - Fork 1
/
p2e.java
executable file
·48 lines (41 loc) · 1.58 KB
/
p2e.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
///usr/bin/env jbang "$0" "$@" ; exit $?
//DEPS info.picocli:picocli:4.7.6
//DEPS info.picocli:picocli-codegen:4.7.6
//MANIFEST Implementation-Version=${version:dev}
//JAVA 23
package com.github.helpermethod.p2e;
import java.util.Locale;
import picocli.CommandLine;
import picocli.CommandLine.Command;
import picocli.CommandLine.IVersionProvider;
import picocli.CommandLine.Parameters;
import static java.lang.System.out;
@Command(
name = "p2e",
mixinStandardHelpOptions = true,
versionProvider = p2e.ManifestVersionProvider.class,
description = "Convert Spring configuration property names to environment variable names."
)
class p2e implements Runnable {
@Parameters(index = "0", description = "The property name")
private String property;
public static void main(String... args) {
System.exit(new CommandLine(new p2e()).execute(args));
}
@Override
public void run() {
// see https://docs.spring.io/spring-boot/docs/current/reference/html/features.html#features.external-config.typesafe-configuration-properties.relaxed-binding.environment-variables
var environmentVariableName =
property
.replace(".", "_")
.replace("-", "")
.replaceAll("\\[(?<index>[0-9]+)]", "_${index}")
.toUpperCase(Locale.ENGLISH);
out.println(environmentVariableName);
}
static class ManifestVersionProvider implements IVersionProvider {
public String[] getVersion() {
return new String[] { getClass().getPackage().getImplementationVersion() };
}
}
}