Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion anarchrypto
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ DIR="$(dirname "$(realpath "$0")")"
SELF="$(realpath "$0")"

# Resolve version from build.gradle so the launcher never goes stale
VERSION=$(grep -oP "^version\s*=\s*'\K[^']+" "$DIR/build.gradle" 2>/dev/null || echo "")
VERSION=$(sed -n "s/^version *= *'\([^']*\)'.*/\1/p" "$DIR/build.gradle" 2>/dev/null)
JAR="$DIR/build/libs/anarcry-${VERSION}.jar"

# Auto-build: rebuild JAR if missing or source is newer
Expand Down
29 changes: 18 additions & 11 deletions src/main/java/gg/effront/anarcry/apiclient/io/BruImporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

public class BruImporter {

private static final Pattern KV_PATTERN = Pattern.compile("^\\s*(~?)\\s*([^:]+):\\s*(.*)$", Pattern.MULTILINE);
private static final Pattern KV_PATTERN = Pattern.compile("^\\s*(~?)\\s*([^:]+):[ \\t]*(.*)$", Pattern.MULTILINE);

private record Block(String tag, String content) {
}
Expand All @@ -40,17 +40,15 @@ private static List<Block> parseBlocks(String text) {
int len = text.length();
int i = 0;
while (i < len) {
// Skip whitespace / blank lines between blocks
while (i < len && Character.isWhitespace(text.charAt(i))) {
i++;
}
if (i >= len) {
break;
}

// Read the tag -- everything up to the opening '{'
int tagStart = i;
while (i < len && text.charAt(i) != '{') {
while (i < len && text.charAt(i) != '{' && text.charAt(i) != '[') {
i++;
}
if (i >= len) {
Expand All @@ -62,17 +60,17 @@ private static List<Block> parseBlocks(String text) {
continue;
}

// Skip the opening '{'
char open = text.charAt(i);
char close = open == '{' ? '}' : ']';
i++;
int depth = 1;
int contentStart = i;

// Walk forward counting braces to find the matching '}'
while (i < len && depth > 0) {
char c = text.charAt(i);
if (c == '{') {
if (c == open) {
depth++;
} else if (c == '}') {
} else if (c == close) {
depth--;
}
if (depth > 0) {
Expand All @@ -83,7 +81,6 @@ private static List<Block> parseBlocks(String text) {
String content = text.substring(contentStart, i).trim();
blocks.add(new Block(tag, content));

// Skip the closing '}'
if (i < len) {
i++;
}
Expand Down Expand Up @@ -302,8 +299,18 @@ private Environment parseEnvironment(Path file) throws IOException {
String blockContent = block.content();
if ("vars".equals(tag) || "vars:secret".equals(tag)) {
boolean secret = tag.contains("secret");
for (var kv : parseKv(blockContent)) {
variables.add(new EnvVariable(kv.key(), kv.value(), secret, kv.enabled()));
List<KvEntry> kvEntries = parseKv(blockContent);
if (!kvEntries.isEmpty()) {
for (var kv : kvEntries) {
variables.add(new EnvVariable(kv.key(), kv.value(), secret, kv.enabled()));
}
} else if (secret) {
for (String entry : blockContent.split("[,\\n]")) {
String trimmed = entry.trim();
if (!trimmed.isEmpty()) {
variables.add(new EnvVariable(trimmed, "", true, true));
}
}
}
}
}
Expand Down
38 changes: 30 additions & 8 deletions src/main/java/gg/effront/anarcry/gui/views/ApiClientView.java
Original file line number Diff line number Diff line change
Expand Up @@ -2375,6 +2375,7 @@ private void openEnvEditor() {
dialog.setVisible(true);
if (dialog.isSaved()) {
currentCollection = dialog.getUpdatedCollection();
resetSessionContext();
populateEnvCombo();
}
}
Expand Down Expand Up @@ -3000,7 +3001,7 @@ private void loadDotEnv(Path dir) {
return;
}
try {
List<EnvVariable> vars = new ArrayList<>();
java.util.Map<String, String> dotEnvMap = new java.util.LinkedHashMap<>();
for (String line : java.nio.file.Files.readAllLines(dotEnv)) {
String trimmed = line.trim();
if (trimmed.isEmpty() || trimmed.startsWith("#")) {
Expand All @@ -3013,16 +3014,33 @@ private void loadDotEnv(Path dir) {
if (value.startsWith("\"") && value.endsWith("\"") && value.length() >= 2) {
value = value.substring(1, value.length() - 1);
}
vars.add(EnvVariable.of(key, value));
dotEnvMap.put(key, value);
}
}
if (!vars.isEmpty()) {
List<Environment> envs = new ArrayList<>(currentCollection.environments());
envs.add(0, new Environment(null, ".env", null, vars, null));
currentCollection = new Collection(currentCollection.uid(), currentCollection.name(),
currentCollection.version(), envs, currentCollection.items(), currentCollection.root(),
currentCollection.settings());
if (dotEnvMap.isEmpty()) {
return;
}

List<Environment> envs = new ArrayList<>();
for (Environment env : currentCollection.environments()) {
List<EnvVariable> merged = new ArrayList<>();
for (EnvVariable v : env.variables()) {
if (v.secret() && v.value().isEmpty() && dotEnvMap.containsKey(v.name())) {
merged.add(new EnvVariable(v.name(), dotEnvMap.get(v.name()), true, v.enabled()));
} else {
merged.add(v);
}
}
envs.add(new Environment(env.uid(), env.name(), env.color(), merged, env.extendsEnv()));
}

List<EnvVariable> dotEnvVars = dotEnvMap.entrySet().stream()
.map(e -> EnvVariable.of(e.getKey(), e.getValue())).toList();
envs.add(0, new Environment(null, ".env", null, dotEnvVars, null));

currentCollection = new Collection(currentCollection.uid(), currentCollection.name(),
currentCollection.version(), envs, currentCollection.items(), currentCollection.root(),
currentCollection.settings());
} catch (Exception ignored) {
}
}
Expand Down Expand Up @@ -3061,13 +3079,17 @@ private void addItemsToNode(DefaultMutableTreeNode parent, List<CollectionItem>
}

private void populateEnvCombo() {
String prev = (String) envCombo.getSelectedItem();
envCombo.removeAllItems();
envCombo.addItem("(no env)");
if (currentCollection != null) {
for (Environment env : currentCollection.environments()) {
envCombo.addItem(env.name());
}
}
if (prev != null) {
envCombo.setSelectedItem(prev);
}
}

private Environment getSelectedEnvironment() {
Expand Down
Loading