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

Commit 352d820

Browse files
author
Aleksi Salmela
committed
Add support for disabling autoupdates.
1 parent eaf3eef commit 352d820

4 files changed

Lines changed: 15 additions & 7 deletions

File tree

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public class Application {
4040
private final Options options;
4141
private final GnuParser parser;
4242
private String commandName;
43+
private boolean noAutoUpdate;
4344

4445
public Application(CliContext context) {
4546
this.parser = new GnuParser();
@@ -51,6 +52,7 @@ public Application(CliContext context) {
5152
options.addOption("h", "help", false, "Display help information about tmc-cli");
5253
options.addOption("v", "version", false, "Give the version of the tmc-cli");
5354
options.addOption("u", "force-update", false, "Force the auto-update");
55+
options.addOption("d", "no-update", false, "Disable temporarily the auto-update");
5456

5557
//TODO implement the inTests as context.property
5658
if (!context.inTests()) {
@@ -94,6 +96,12 @@ private String[] parseArgs(String[] args) {
9496
boolean showHelp = line.hasOption("h");
9597
boolean showVersion = line.hasOption("v");
9698
boolean forceUpdate = line.hasOption("u");
99+
this.noAutoUpdate = line.hasOption("d");
100+
101+
if (forceUpdate && this.noAutoUpdate) {
102+
io.errorln("You can't use --force-update and --no-update at same time.");
103+
return null;
104+
}
97105

98106
if (showHelp) {
99107
// don't run the help sub-command with -h switch
@@ -127,7 +135,7 @@ public void run(String[] args) {
127135
return;
128136
}
129137

130-
if (!context.inTests() && versionCheck()) {
138+
if (!context.inTests() && !noAutoUpdate && versionCheck()) {
131139
return;
132140
}
133141

src/main/java/fi/helsinki/cs/tmc/cli/command/LoginCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public void run(CliContext context, CommandLine args) {
4040
this.ctx = context;
4141
this.io = ctx.getIo();
4242

43-
if(args.getArgs().length > 0) {
43+
if (args.getArgs().length > 0) {
4444
io.errorln("Login doesn't take any arguments.");
4545
printUsage(context);
4646
return;

src/main/java/fi/helsinki/cs/tmc/cli/command/LogoutCommand.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public void getOptions(Options options) {
1919
@Override
2020
public void run(CliContext context, CommandLine args) {
2121
Io io = context.getIo();
22-
if(args.getArgs().length > 0) {
22+
if (args.getArgs().length > 0) {
2323
io.errorln("Logout doesn't take any arguments.");
2424
printUsage(context);
2525
return;

src/main/java/fi/helsinki/cs/tmc/cli/core/AbstractCommand.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ protected void printUsage(CliContext context) {
9494
}
9595

9696
private Command getCommand() {
97-
if(this.command == null) {
97+
if (this.command == null) {
9898
Class<Command> klass;
9999
klass = CommandFactory.castToCommandClass(this.getClass());
100100
this.command = CommandFactory.getCommand(klass);
@@ -121,14 +121,14 @@ private void printHelp(CliContext context) {
121121
private String getUsageString() {
122122
String prefix = "tmc " + getCommand().name() + " ";
123123
String[] usages = getUsages();
124-
if(usages == null) {
124+
if (usages == null) {
125125
return prefix;
126126
}
127127

128128
StringBuilder builder = new StringBuilder();
129129
boolean first = true;
130-
for(String line : usages) {
131-
if(!first) {
130+
for (String line : usages) {
131+
if (!first) {
132132
builder.append("\n");
133133
}
134134
builder.append(prefix);

0 commit comments

Comments
 (0)