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

Commit 751c5cc

Browse files
author
Aleksi Salmela
committed
Split the execute method of AbstractCommand.
This makes debugging faster when you want to go to the command's code.
1 parent 35ffc92 commit 751c5cc

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

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

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,13 @@ private Options getOptions() {
5757
public abstract void run(CommandLine args, Io io);
5858

5959
public void execute(String[] stringArgs, Io io) {
60+
CommandLine args = parseArgs(stringArgs, io);
61+
if (args != null) {
62+
run(args, io);
63+
}
64+
}
65+
66+
public CommandLine parseArgs(String[] stringArgs, Io io) {
6067
GnuParser parser = new GnuParser();
6168
CommandLine args;
6269
Options options = getOptions();
@@ -67,7 +74,7 @@ public void execute(String[] stringArgs, Io io) {
6774
logger.warn("Invalid command line arguments.", e);
6875
io.println("Invalid command line arguments.");
6976
io.println(e.getMessage());
70-
return;
77+
return null;
7178
}
7279

7380
if (args.hasOption("h")) {
@@ -81,9 +88,8 @@ public void execute(String[] stringArgs, Io io) {
8188
desc = command.desc();
8289
}
8390
HelpGenerator.run(io, usage, desc, options);
84-
return;
91+
return null;
8592
}
86-
87-
run(args, io);
93+
return args;
8894
}
8995
}

0 commit comments

Comments
 (0)