Skip to content

Commit

Permalink
Added cli option to specify the target version to update to
Browse files Browse the repository at this point in the history
  • Loading branch information
Podshot committed Nov 28, 2020
1 parent ebddb3e commit 658529b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
7 changes: 6 additions & 1 deletion src/main/java/com/amulet_editor/amulet_updater/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,13 @@ public static void main(String[] args) {
options.addOption("pid", true, "The PID to kill");
options.addOption("install_beta", "Switch to install the beta version");
options.addOption("current_version", true, "The currently installed version");
options.addOption("target_version",true, "The target version to update to");

CommandLineParser parser = new DefaultParser();

String workingDirectory = null;
String currentVersion = null;
String targetVersion = null;
boolean installBeta = false;
String sPid = null;

Expand All @@ -61,6 +63,9 @@ public static void main(String[] args) {
if (cli.hasOption("pid")) {
sPid = cli.getOptionValue("pid");
}
if (cli.hasOption("target_version")) {
targetVersion = cli.getOptionValue("target_version");
}
} catch (ParseException exp) {
exp.printStackTrace();
}
Expand All @@ -73,7 +78,7 @@ public static void main(String[] args) {
environment.put(Constants.WORKING_DIRECTORY, new File(workingDirectory));
environment.put(Constants.CURRENT_VERSION, currentVersion);

GithubAPI.ReleaseInfo releaseInfo = GithubAPI.getLatestRelease(installBeta);
GithubAPI.ReleaseInfo releaseInfo = GithubAPI.getLatestRelease(installBeta, targetVersion);
if (releaseInfo == null) {
JOptionPane.showMessageDialog(UpdateUI.getInstanceComponent(), "Couldn't find latest release, please wait 1 hour and try again", "An Error has Occured", JOptionPane.ERROR_MESSAGE);
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public class GithubAPI {
private static final Github github = new RtGithub();

public static void main(String[] args) throws MalformedURLException {
ReleaseInfo info = getLatestRelease(false);
ReleaseInfo info = getLatestRelease(false, null);
assert info != null;
System.out.println(info.releaseVersion + " -> " + info.parseUrl(info.getReleaseAsset()));
}
Expand Down Expand Up @@ -60,7 +60,7 @@ public URL parseUrl(String assetName) throws MalformedURLException {
}
}

public static ReleaseInfo getLatestRelease(boolean includeBetas) {
public static ReleaseInfo getLatestRelease(boolean includeBetas, String targetVersion) {
try {
Repo repo = github.repos().get(
new Coordinates.Simple("Amulet-Team/Amulet-Map-Editor")
Expand All @@ -75,7 +75,11 @@ public static ReleaseInfo getLatestRelease(boolean includeBetas) {
}

if (!latestRelease.draft()) {
break;
if (targetVersion == null) {
break;
} else if (targetVersion.equals(latestRelease.tag())) {
break;
}
}
}
if (latestRelease != null) {
Expand Down

0 comments on commit 658529b

Please sign in to comment.