Skip to content
This repository was archived by the owner on Jun 3, 2025. It is now read-only.

Commit 77643e1

Browse files
author
Aleksi Salmela
committed
Implement force auto-update flag.
1 parent 1b834ce commit 77643e1

2 files changed

Lines changed: 21 additions & 6 deletions

File tree

src/main/java/fi/helsinki/cs/tmc/cli/Application.java

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import fi.helsinki.cs.tmc.cli.io.HelpGenerator;
88
import fi.helsinki.cs.tmc.cli.io.Io;
99
import fi.helsinki.cs.tmc.cli.io.ShutdownHandler;
10-
import fi.helsinki.cs.tmc.cli.tmcstuff.WorkDir;
1110
import fi.helsinki.cs.tmc.cli.updater.TmcCliUpdater;
1211

1312
import org.apache.commons.cli.CommandLine;
@@ -49,6 +48,7 @@ public Application(CliContext context) {
4948

5049
options.addOption("h", "help", false, "Display help information about tmc-cli");
5150
options.addOption("v", "version", false, "Give the version of the tmc-cli");
51+
options.addOption("f", "force-update", false, "Force the auto-update");
5252

5353
//TODO implement the inTests as context.property
5454
if (!context.inTests()) {
@@ -90,7 +90,11 @@ private String[] parseArgs(String[] args) {
9090
return null;
9191
}
9292

93-
if (line.hasOption("h")) {
93+
boolean showHelp = line.hasOption("h");
94+
boolean showVersion = line.hasOption("v");
95+
boolean forceUpdate = line.hasOption("f");
96+
97+
if (showHelp) {
9498
// don't run the help sub-command with -h switch
9599
if (commandName.equals("help")) {
96100
runCommand("help", new String[0]);
@@ -99,10 +103,14 @@ private String[] parseArgs(String[] args) {
99103
runCommand(commandName, new String[]{"-h"});
100104
return null;
101105
}
102-
if (line.hasOption("v")) {
106+
if (showVersion) {
103107
io.println("TMC-CLI version " + EnvironmentUtil.getVersion());
104108
return null;
105109
}
110+
if (forceUpdate) {
111+
runAutoUpdate();
112+
return null;
113+
}
106114
return subArgs.toArray(new String[subArgs.size()]);
107115
}
108116

@@ -113,12 +121,12 @@ public void printHelp(String description) {
113121
public void run(String[] args) {
114122
context.setApp(this);
115123

116-
if (!context.inTests() && versionCheck()) {
124+
String[] commandArgs = parseArgs(args);
125+
if (commandArgs == null) {
117126
return;
118127
}
119128

120-
String[] commandArgs = parseArgs(args);
121-
if (commandArgs == null) {
129+
if (!context.inTests() && versionCheck()) {
122130
return;
123131
}
124132

@@ -156,6 +164,12 @@ private boolean versionCheck() {
156164
return false;
157165
}
158166

167+
return runAutoUpdate();
168+
}
169+
170+
public boolean runAutoUpdate() {
171+
Map<String, String> properties = context.getProperties();
172+
Date now = new Date();
159173
TmcCliUpdater update = new TmcCliUpdater(io, EnvironmentUtil.getVersion(),
160174
EnvironmentUtil.isWindows());
161175
boolean updated = update.run();

src/main/java/fi/helsinki/cs/tmc/cli/tmcstuff/TmcUtil.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ protected static void handleTmcExceptions(CliContext ctx, Exception exception) {
203203
if (cause instanceof ObsoleteClientException) {
204204
logger.error("Outdated tmc client");
205205
io.println("Your tmc-cli is outdated. Please update it.");
206+
ctx.getApp().runAutoUpdate();
206207
return;
207208
}
208209
logger.error("Command failed in tmc-core", exception);

0 commit comments

Comments
 (0)