Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,11 @@ public class InstallModrinthModpackCommand implements Callable<Integer> {
)
String modpackProject;

@Option(names = "--version-id", description = "Version ID (not name) from the file's metadata")
String versionId;
@Option(names = {"--version-id", "--version"},
description = "Version ID, name, or number from the file's metadata" +
"%nDefault chooses newest file based on game version, loader, and/or default version type"
)
String version;

@Option(names = "--game-version", description = "Applicable Minecraft version" +
"%nDefault: (any)")
Expand Down Expand Up @@ -109,12 +112,12 @@ public Integer call() throws Exception {
final Matcher m = MODPACK_PAGE_URL.matcher(modpackProject);
if (m.matches()) {
final String versionName = m.group("versionName");
if (versionName != null && versionId != null) {
throw new InvalidParameterException("Cannot provide both project file URL and version ID");
if (versionName != null && version != null) {
throw new InvalidParameterException("Cannot provide both project file URL and version");
}
projectRef = new ProjectRef(m.group("slug"), versionId, versionName);
projectRef = new ProjectRef(m.group("slug"), versionName != null ? versionName : version);
} else {
projectRef = new ProjectRef(modpackProject, versionId, null);
projectRef = new ProjectRef(modpackProject, version);
}

final ModrinthModpackManifest newManifest =
Expand Down Expand Up @@ -150,7 +153,7 @@ private ModrinthModpackManifest processModpack(ProjectRef projectRef, ModrinthMo
.filter(version -> needsInstall(prevManifest, project, version))
.flatMap(version -> {
final VersionFile versionFile = pickVersionFile(version);
log.debug("Picked versionFile={} from version={}", versionFile, version);
log.info("Installing version {} of {}", version.getVersionNumber(), project.getTitle());
return apiClient.downloadMrPack(versionFile)
.publishOn(Schedulers.boundedElastic())
.flatMap(zipPath ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ public Mono<Version> resolveProjectVersion(Project project, ProjectRef projectRe
return getVersionsForProject(project.getId(), loader, gameVersion)
.flatMap(versions ->
Mono.justOrEmpty(versions.stream()
.filter(version -> version.getName().equals(projectRef.getVersionName()))
.filter(version ->
version.getVersionNumber().equals(projectRef.getVersionName())
|| version.getName().equals(projectRef.getVersionName())
)
.findFirst()
));
}
Expand Down
72 changes: 48 additions & 24 deletions src/main/java/me/itzg/helpers/modrinth/ProjectRef.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,55 +4,79 @@
import lombok.ToString;
import me.itzg.helpers.modrinth.model.VersionType;

import java.util.regex.Pattern;

@ToString
public class ProjectRef {
private static final Pattern VERSIONS = Pattern.compile("[a-zA-z0-9]{8}");

@Getter
final String idOrSlug;
final String versionIdOrType;
@Getter
final VersionType versionType;
@Getter
final String versionId;
@Getter
final String versionName;

public static ProjectRef parse(String projectRef) {
final String[] projectRefParts = projectRef.split(":", 2);

return new ProjectRef(projectRefParts[0],
projectRefParts.length > 1 ? projectRefParts[1] : null,
null
projectRefParts.length > 1 ? projectRefParts[1] : null
);
}

public ProjectRef(String projectSlug, String versionIdOrType, String versionName) {
/**
*
* @param version can be a {@link VersionType}, ID, or name/number
*/
public ProjectRef(String projectSlug, String version) {
this.idOrSlug = projectSlug;
this.versionIdOrType = versionIdOrType;
this.versionName = versionName;
this.versionType = parseVersionType(version);
if (this.versionType == null) {
if (isVersionId(version)) {
this.versionId = version;
this.versionName = null;
}
else {
this.versionId = null;
this.versionName = version;
}
}
else {
this.versionId = null;
this.versionName = null;
}
}

public boolean hasVersionName() {
return versionName != null;
private boolean isVersionId(String version) {
if (version == null) {
return false;
}
return VERSIONS.matcher(version).matches();
}

public boolean hasVersionType() {
if (versionIdOrType != null) {
try {
VersionType.valueOf(versionIdOrType);
return true;
} catch (IllegalArgumentException e) {
return false;
}
private VersionType parseVersionType(String version) {
if (version == null) {
return null;
}
try {
return VersionType.valueOf(version);
} catch (IllegalArgumentException e) {
return null;
}
return false;
}

public VersionType getVersionType() {
return VersionType.valueOf(versionIdOrType);
public boolean hasVersionName() {
return versionName != null;
}

public boolean hasVersionId() {
return versionIdOrType != null &&
!hasVersionType();
public boolean hasVersionType() {
return versionType != null;
}

public String getVersionId() {
return versionIdOrType;
public boolean hasVersionId() {
return versionId != null;
}
}
2 changes: 1 addition & 1 deletion src/main/java/me/itzg/helpers/modrinth/model/Version.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class Version {

Instant datePublished;

String version;
String versionNumber;

VersionType versionType;

Expand Down